Often I get unintelligible errors from compilers and trying to Google for an answer returns nothing of use, so I thought I would put up errors on this post as I run into them to help other people who have a similar problem.
Most of it will probably be C compiled under GCC but I play with C++, C#, Java, Python also and sometimes use other compilers such as Sun’s. If you have an alternative solution to an error post it to the comments and ill add it when I have time ☺
error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
Possible cause, forgetting to put () after function name in the function declaration
Example:
Universe* createUniverse {
Universe universe = malloc(sizeof(Universe));
bigBang(universe);
return universe;
}
Should be:
Universe* createUniverse() {
Universe universe = malloc(sizeof(Universe));
bigBang(universe);
return universe;
}
expected expression before '=' token
This was on the same line as a for loop for me me but was actually caused by accidentally having an = in the #define of a constant, this can be overlooked because the #defines are separate area and not thought about much once set:
#define NUM_STARS = 100000
Should be:
#define NUM_STARS 100000
error: invalid initializer
Can be cause by forgetting to declare variable as a pointer with *
Node newNode = appendNode(node);
Should be:
Node* newNode = appendNode(node);
error: expected `)' before ‘;’ token
Can be cause by putting a ; in place of ,
Example:
#include
using namespace std;
int main(int argc; char* argv[]) {
cout << "Hello World" <<; endl;
exit(EXIT_SUCCESS);
}
Should be:
#include
using namespace std;
int main(int argc, char* argv[]) {
cout << "Hello World" << endl;
exit(EXIT_SUCCESS);
}
Recent Comments