getting C129 on empty file

I have two files fsm_right.c and fsm_left.c

in my main program, before any other header files, I have this

#define FSM 1

#ifdef FSM #ifdef FMSLEFT // note: currently undefined include "fsm_left.c" #else include "fsm_right.c" #endif
#endif

the next line is

unsigned char author= "whatever";

The compiler spits up on the assignment line, with a C129 missing ';' before <string>

So I figured, something in fsm_right was incorrect. To test this, I commented out the
include "fsm_right.c" (and this same thing happens with the <fsm_right.c> syntax.
The program compiles without a problem.
So I figured the problem was in fsm_right.c
I edited fms_right.c and deleted EVERYTHING in it, so it is just a blank file.

And it *STILL* has the error. This is version 7.5 by the way.
K&RC say that the include statement is replaced by the contents of the file.

What in the world is going on here?
With the include commented out //include ..... it compiles fine.
With the include NOT commented out, it gives the error WHETHER OR NOT there is anything in the body of the included file.

This makes no sense. Is there a bug in the pre-processor? environment is windows XP running Silabs IDE with the Keil 7.5 as the compiler. I've seen this before, could not figure it out and went a different direction, but now I need to have it this way.

The project consists of a main file, and a second C file with some constants and structures. I compile them seperately and link them. Now I need to build two new configurations, to be controlled by compile time switches. I don't want to put fsm_left and fsm_right into the structure file, because then I would have to set the define in that file, as well as the main file, and this can result in building the wrong device. The main file compiles code for 3 seperate products based on compile time switches. The 3 devices share a common set of structures, though not all of them are used by each build.

Parents
  • in my main program, before any other header files, I have this

    No, you don't. Because whatever you actually have, I'm really quite sure it doesn't look like that:

    #define FSM 1

    #ifdef FSM #ifdef FMSLEFT // note: currently undefined include "fsm_left.c" #else include "fsm_right.c" #endif
    #endif

    but rather more like this:

    #define FSM 1
    
    #ifdef FSM
    # ifdef FMSLEFT // note: currently undefined
    #  include "fsm_left.c"
    # else
    #  include "fsm_right.c"
    # endif
    #endif
    

    Programming is all about attention to detail. So please pay attention to the formatting instructions, next time. They're right above the input window, for crying out loud!

    The compiler spits up on the assignment line, with a C129 missing ';' before

    "The assignment line" being this one?

    unsigned char author= "whatever";
    

    Now stop and sit down for a moment. Does that really look like valid C code that the compiler should have accepted?

    So I figured, something in fsm_right was incorrect.

    And how did you figure that, given the error message was apparently about a line in your main source file, rather than in fsm_right.c?

    I don't want to put fsm_left and fsm_right into the structure file,

    Pray tell: what do you mean by "the structure file"?

    because then I would have to set the define in that file, as well as the main file, and this can result in building the wrong device.

    No you wouldn't have to do that. Making sure multiple C modules use the same set of compiler switches is trivially easy without having to revert back that far. That's what common header files and/or IDE/Makefile settings of compiler switches are for.

Reply
  • in my main program, before any other header files, I have this

    No, you don't. Because whatever you actually have, I'm really quite sure it doesn't look like that:

    #define FSM 1

    #ifdef FSM #ifdef FMSLEFT // note: currently undefined include "fsm_left.c" #else include "fsm_right.c" #endif
    #endif

    but rather more like this:

    #define FSM 1
    
    #ifdef FSM
    # ifdef FMSLEFT // note: currently undefined
    #  include "fsm_left.c"
    # else
    #  include "fsm_right.c"
    # endif
    #endif
    

    Programming is all about attention to detail. So please pay attention to the formatting instructions, next time. They're right above the input window, for crying out loud!

    The compiler spits up on the assignment line, with a C129 missing ';' before

    "The assignment line" being this one?

    unsigned char author= "whatever";
    

    Now stop and sit down for a moment. Does that really look like valid C code that the compiler should have accepted?

    So I figured, something in fsm_right was incorrect.

    And how did you figure that, given the error message was apparently about a line in your main source file, rather than in fsm_right.c?

    I don't want to put fsm_left and fsm_right into the structure file,

    Pray tell: what do you mean by "the structure file"?

    because then I would have to set the define in that file, as well as the main file, and this can result in building the wrong device.

    No you wouldn't have to do that. Making sure multiple C modules use the same set of compiler switches is trivially easy without having to revert back that far. That's what common header files and/or IDE/Makefile settings of compiler switches are for.

Children
More questions in this forum