• Advertisement
Sign in to follow this  

struct declaration c/c++/obj-c

This topic is 2634 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What is the difference between:

struct MyStruct
{
...
};

and

typedef struct
{
...
} MyStruct;

The second allows my obj-c code to compile, and the first does not.

Share this post


Link to post
Share on other sites
Advertisement
The first is C++ syntax. The latter is C syntax. obj-c is a superset of C, not C++. However, if you want XCode to compile the former, rename your file to .mm instead of .m

That will allow you to reference and use C++ code. Just remember when you start getting weird compile errors that any file that includes a header with C++ syntax must also have the .mm filename. When I'm starting a new iPhone project, the first thing I do is just rename everything to be .mm. That way I don't have to worry about it :)

-me

Share this post


Link to post
Share on other sites
Awesome. Given that c++ is backward compatible with c, is there any reason one would NOT want to just make everything a .mm?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement