I created a #define called MAX_DATA_SIZE in an include file here:
https://github.com/randomguy70/smartNotesRewrite/blob/d15753a303f54bb75c7a456550bbf29978bbeb6a/src/file.h#L23C14-L23C14
and I tried to use MAX_DATA_SIZE in another include file here when creating a struct:
https://github.com/randomguy70/smartNotesRewrite/blob/d15753a303f54bb75c7a456550bbf29978bbeb6a/src/editor.h#L41
and I always get an error saying that MAX_DATA_SIZE is an undeclared identifier, although I know the compiler recognizes it as defined because it ran this code.
Code:
#ifdef MAX_DATA_SIZE
#warning it's defined
#endif
Thank you in advance!
I have no immediate answer to your problem, but a useful technique to debug preprocessor issues like this is to have the compiler stop after running the preprocessor by passing -E. I see from your repository that you're building with a Makefile so you can find the invocation of ez80-clang that your problematic .c file is being built with, then add -E to make it emit the preprocessed output so you can see what definitions are being inserted (and I believe where they come from).
randomguy wrote:
and I always get an error saying that MAX_DATA_SIZE is an undeclared identifier, although I know the compiler recognizes it as defined because it ran this code.
Code:
#ifdef MAX_DATA_SIZE
#warning it's defined
#endif
Did you insert this code near your struct definition, or near where MAX_DATA_SIZE is defined? I see you have some other header definitions between including file.h and declaring that struct: do those other headers #undef MAX_DATA_SIZE?
You are including editor.h inside of file.h before MAX_DATA_SIZE is defined.
As a general rule, header files should be written to not depend on other header files (besides system/library ones)
KermMartian wrote:
randomguy wrote:
and I always get an error saying that MAX_DATA_SIZE is an undeclared identifier, although I know the compiler recognizes it as defined because it ran this code.
Code:
#ifdef MAX_DATA_SIZE
#warning it's defined
#endif
Did you insert this code near your struct definition, or near where MAX_DATA_SIZE is defined? I see you have some other header definitions between including file.h and declaring that struct: do those other headers #undef MAX_DATA_SIZE?
I put that code right before the struct definition.
MateoConLechuga wrote:
You are including editor.h inside of file.h before MAX_DATA_SIZE is defined.
As a general rule, header files should be written to not depend on other header files (besides system/library ones)
Should I just substitute the integer value 3000 for MAX_DATA_SIZE in editor.h? I thought it was good to use #defines to organize &/ keep track of magic numbers.
Edit: I moved the Code: #include "editor.h"
that was originally in file.h into file.c. (Not exactly sure what I was thinking before).
randomguy wrote:
MateoConLechuga wrote:
]
You are including editor.h inside of file.h before MAX_DATA_SIZE is defined.
As a general rule, header files should be written to not depend on other header files (besides system/library ones)
Should I just substitute the integer value 3000 for MAX_DATA_SIZE in editor.h? I thought it was good to use #defines to organize &/ keep track of magic numbers.
No, you should write your code better.
This may not be related to your issue, but why do you have this
line before the declaration of the structure?
Captain Calc wrote:
This may not be related to your issue, but why do you have this
line before the declaration of the structure?
Because he's one of those heathens that uses global variables
Captain Calc wrote:
This may not be related to your issue, but why do you have this
line before the declaration of the structure?
I am indeed a heathen who uses global variables. In this case, I was messing around with the order of struct declarations to see how the compiler would respond.
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.
»
Go to Registration page
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum