Pages: [1]   Go Down
Author Topic: lont vs long  (Read 307 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 1
Posts: 170
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't know if this is really a bug, but it bugged me smiley

I was working on a library.  In the .h file, I wanted to declare a variable of type long, eg

  long StartMillisRead;

but instead I typed lont, eg

  lont StartMillisRead;

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?


Logged

0
Offline Offline
Faraday Member
**
Karma: 7
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You shouldn't declare variables in a header file.  headers are for non-executable stuff.

If you're writing a library, you should define the variable in the header file (e.g. extern int myGlobalVariable; ), and declare it in the .c (or .cpp) file (int myGlobalVariable;).

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 near the error message.

-j
« Last Edit: June 22, 2009, 07:25:49 am by kg4wsv » Logged

Pages: [1]   Go Up
Jump to: