This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

#define statements on variable declarations

Hello. I am trying to find new and exciting ways to optimize (read: shrink down) my current code and want to include an eeprom autorefresh option to cut down on variables. Basically, when I have the AutoRefreshCompile option set, I want it to create the variable "randomvariable". My code is pretty simple:

#define AutoRefreshCompile 1

        #if(AutoRefreshCompile==1)
        {  // line x
                extern signed short randomvariable;
        }  // line y
        #endif

I am getting errors that read as follows:


VARS.H(x) error C141: syntax error near '{'
VARS.H(y) error C141: syntax error near '}'

I'm guessing it is not possible to do this (if I remember correctly, variables have to be declared at the beginning and can't be in the middle of functions/code segments but maybe it's some really simple fix.

I realize this might not work but I figure it's worth a shot. Any suggestions? Thanks!

Parents
  • Using brackets is actually not an issue in normal .C files either, which is why I hadn't seen this issue til now. The issue is specific to .H files
    NO!, NO!, NO!

    brackets are specific to (a group of) statements and screw up preprocessor directives, whether in a .c or a .h file.

    sometimes I don't understand your posts. I can't decide whether the intention is to make obvious statements that we both know the answer to, to make me feel stupid, or if you didn't read some of the previous posts
    not to make you feel stupid, but it is clear you are confoosed. DO NOT 'hurry up and get going' get this down solidly before you go on. As stated above, you have still some preconceived issues remaining. FORGET what you 'thought' and start from scratch learning this.

    if you (or anyone else, really) had told me a few posts ago that my fundamental understanding was in directives vs statements rather than telling me to go find a C book and start reading, it could've saved us all a lot of time.
    an answer in a post will clear up e.g. a set of misplaced brackets and nothing else. Reading a book will make you get the concept.

    Erik

Reply
  • Using brackets is actually not an issue in normal .C files either, which is why I hadn't seen this issue til now. The issue is specific to .H files
    NO!, NO!, NO!

    brackets are specific to (a group of) statements and screw up preprocessor directives, whether in a .c or a .h file.

    sometimes I don't understand your posts. I can't decide whether the intention is to make obvious statements that we both know the answer to, to make me feel stupid, or if you didn't read some of the previous posts
    not to make you feel stupid, but it is clear you are confoosed. DO NOT 'hurry up and get going' get this down solidly before you go on. As stated above, you have still some preconceived issues remaining. FORGET what you 'thought' and start from scratch learning this.

    if you (or anyone else, really) had told me a few posts ago that my fundamental understanding was in directives vs statements rather than telling me to go find a C book and start reading, it could've saved us all a lot of time.
    an answer in a post will clear up e.g. a set of misplaced brackets and nothing else. Reading a book will make you get the concept.

    Erik

Children
  • No, that's not true.

    If the preprocessor directives, after preprocessing, leave any syntax error, then you'll get diagnostics about those errors.

    In this case, the preprocessor directives, after preprocessing, left misplaced braces - so the OP got diagnostics about those misplaced braces.

    It's not that the braces in any way "interfered with" or "screwed-up" the preprocessor directives.