Sunday, June 26, 2011

Programming: C++ And C

C++ compilers (g++ or visual c++ for example) can compile many C codes, but not necessarily all of them. Here is a simple but lame example:

int class, template;

Above code compiles fine with a C code but not with C++, as 'class' and 'template' are keywords in C++. But again, it's really a lame example.

A good example is the feature set of C99. Here are some codes that are valid in C but not in C++:

int vec[5] = { [1]=10, [3]=20 }; // designated initializers

typedef struct
char name[20];
int ID;
int age;

Employee emp = {.ID = 0, .age = 0};

int main()

The reason for not having the support for the C99 code in some major C++ compilers is that C++ was standardized in 98 and C99 standards came after that.
WordLight is a nice little add-in for Visual Studio 2008. When you select some text in the editor, it searches and highlights the same string in rest of the code.


If you have VisualAssist, you may not need this. Otherwise, you'll enjoy this add-in.

No comments:

Post a Comment