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
  • In the primary post the error message is:

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

    The file name VARS.H implies it is a header file.
    Header files should not contain code, so your snippet:

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

    is (I assume, because I can't know) not part of a function code but part of a declaration.

    If this is true then of course the { and } are not allowed, simply write:

    #define AutoRefreshCompile 1
    
            #if(AutoRefreshCompile==1)
                    extern signed short randomvariable;
            #endif
    

    or something like that...

    #define AutoRefreshCompile
    
    #ifdef AutoRefreshCompile
    extern signed short randomvariable;
    #endif
    

    If this is not true, ignore my answer.

Reply
  • In the primary post the error message is:

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

    The file name VARS.H implies it is a header file.
    Header files should not contain code, so your snippet:

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

    is (I assume, because I can't know) not part of a function code but part of a declaration.

    If this is true then of course the { and } are not allowed, simply write:

    #define AutoRefreshCompile 1
    
            #if(AutoRefreshCompile==1)
                    extern signed short randomvariable;
            #endif
    

    or something like that...

    #define AutoRefreshCompile
    
    #ifdef AutoRefreshCompile
    extern signed short randomvariable;
    #endif
    

    If this is not true, ignore my answer.

Children
No data