C/CPP: question about a strange way to make a obj array.
So I was browsing around when a some one's screenshot caught my eye.
http://download.freshmeat.net/screenshots/55565.png You're probably thinking I'm going to refer to the code in the picture, and you're right. Here is the snippet of code I thought was interesting: Code:
/*...*/ Code:
error_mark error_marks [MAX_MARKS]; |
The declaration
Code:
struct error_mark { The declaration Code:
struct error_mark error_marks [MAX_MARKS]; If you try to Code:
error_mark error_marks [MAX_MARKS]; Code:
#define MAX_MARKS 100 Code:
cc array.c -o array Code:
#define MAX_MARKS 100 In the program any element would be referred to simply as Code:
... |
O, I only tried compiling the code in c++ not c. C++(gcc/g++) doesn't throw out errors for the following:
Code:
#include <iostream> |
/*...*/
struct error_mark { /*...*/ }; struct error_mark error_marks [MAX_MARKS]; /*...*/ if you just wanna: error_mark error_marks [MAX_MARKS]; for that you need to precede the struct..... declaration by "typedef" : /*...*/ typedef struct error_mark { /*...*/ }; error_mark error_marks [MAX_MARKS]; /*...*/ this thing will not give an error now. But one should avoid using "tpedef". |
All times are GMT -5. The time now is 12:48 PM. |