Forum 2005-2010 (read only)
Bugs & Suggestions
lont vs long
Topic: lont vs long
(Read 380 times)
lont vs long
Jun 22, 2009, 06:34 am
I don't know if this is really a bug, but it bugged me
I was working on a library. In the .h file, I wanted to declare a variable of type
but instead I typed
The compiler didn't report an error in the .h file like I would have expected, but instead reported it in the .cpp file when I tried using the variable. While the important thing is that it showed an error, any reason it didn't say something like "unknown variable type" in the .h file?
Re: lont vs long
Jun 22, 2009, 02:25 pm
: Jun 22, 2009, 02:25 pm by kg4wsv
You shouldn't declare variables in a header file. headers are for non-executable stuff.
If you're writing a library, you should
the variable in the header file (e.g.
extern int myGlobalVariable;
it in the .c (or .cpp) file (
Now that that's out of the way, the strangeness you see is because .h files are consumed by the preprocessor before the compiler actually runs, so any errors in the .h file will be reported when the compiler processes the source code file than #includes the header. Header files are not actually compiled directly by the compiler.
Compilers have advanced in how they report error messages, so hopefully there is a clue to the actual location of the error
the error message.