This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/EK-TM4C1294XL: #define preprocessor directive only works on the files in the project folder?

Part Number: EK-TM4C1294XL

Tool/software: TI C/C++ Compiler

I tried the "#define EXAMPLE {x = 10;} " in blinky.c, sum.c and sysctl.c.  x is a global variable and is declared earlier.  All of the files are individual file, and blicky.c and sum.c are in the blinky project folder, but sysctl.c is in the C:\ti\TivaWare_C_Series-2.1.4.178\driverlib directory.  

1) When I place the "EXAMPLE" into 3 of these files, only blinky.c and sum.c get x = 10 at the place of "EXAMPLE", any functions in sysctl.c has no "x = 10" replaced with no error.  It just simply ignored and passing way.

2)After coping the sysctl.c and sysctl.c into the blinky project folder and changing #include path, all the functions in the 3 files work the same and get "x = 10".

Can anyone explain the reason?  May it be the setting for the compiler or CCS itself?.  Thanks

  • Neil Lu said:
    When I place the "EXAMPLE" into 3 of these files, only blinky.c and sum.c get x = 10 at the place of "EXAMPLE", any functions in sysctl.c has no "x = 10" replaced with no error.  It just simply ignored and passing way.

    Use the build option --gen_preprocessor_listing to work out preprocessor problems like this.  Please search for that option in the TI ARM compiler manual.

    Thanks and regards,

    -George

  • Thank you, George, before I submitted for the help, I have tried it and even though tried all the options. They are not working. If you can make it work, just let me know. Thanks, Neil
  • Neil Lu said:
    They are not working.

    Please describe exactly what you see that makes you think it doesn't work.

    Thanks and regards,

    -George

  • Hi, George, thank you for your quick response, and let me repeat it again: when trying all the options and there is nothing happened for the directive and it seems that the preprocessor does nothing if the file is not in project folder

    1) When I place the "EXAMPLE" into 3 of these files, only blinky.c and sum.c get x = 10 at the place of "EXAMPLE", any functions in sysctl.c has no "x = 10" replaced without error message. It just simply ignores and passes by.

    2)Because all the options do not work, and I guessed it may be the CCS or Compiler has bugs or not implemented well. I simply copied the sysctl.c and sysctl.h into the blinky project folder and changed #include to project folder, all the functions in the 3 files work perfect and get "x = 10".

    3) In short words, if the files is not in the project folder, no matter what option you choose, it just does not substitute "x = 10" for the "EXAMPLE" and there is no error message. When I use the debug to look at the processing, it just passes by without doing anything.

    4) If I copy them all in the project folder, all works perfectly.
  • By way, it is not hard to replicate this. Why don't you just use the blicky.c in your hand and just add the #define whatever 1 directive, then place whatever in blicky.c and also place whatever in any file which does not in the blicky.c project. You will see what happens. Thanks,
  • Please send me two CCS projects.  One where this happens ...

    Neil Lu said:
    1) When I place the "EXAMPLE" into 3 of these files, only blinky.c and sum.c get x = 10 at the place of "EXAMPLE", any functions in sysctl.c has no "x = 10" replaced without error message. It just simply ignores and passes by.

    And a different project where this happens ...

    Neil Lu said:
    2)Because all the options do not work, and I guessed it may be the CCS or Compiler has bugs or not implemented well. I simply copied the sysctl.c and sysctl.h into the blinky project folder and changed #include to project folder, all the functions in the 3 files work perfect and get "x = 10".

    Put each project into a zip by carefully following the directions in the article Sharing Projects.  Attach both zip files to your next post.

    Thanks and regards,

    -George

  • Thank you, George, for your reply, I am sorry I cannot sent my projects to you, because it contains more code for the company things which may cause you more headache than the simple blinky . As I suggested to you, it is very simple and easy to do by your environment and condition. You can follow the following steps:

    1. you can directly download and use your "TivaWare_C_sSeries-2.1.4.178";

    2. open the blicky project and set up the workspace in your PC;

    3. Add a test.h file in the project which defines the "#define EXAMPLE 10" in the project folder;

    4. you should #include "test.h" in blinky.c and the files which contain EXAMPLE directive.

    5. Place the EXAMPLE some place in blinky.c and place EXAMPLE in Someplaces in other functions, such as SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION), or SysCtlPeripheralReady(SYSCTL_PERIPH_GPION), or GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0).

    6. set breakpoints at the functions that contain EXAMPLE directive;

    7. Run CCS in debug,

    8. When you trace into it, you will find what I mentioned previously, any EXAMPLE in the project folder will be replaced by 10, but skipped if EXAMPLE is not in the project folder.

    9. You may also create a very simple function, one put in the project folder and another put in other folder. Making thing simple is the best!
  • I'm sorry, but I don't understand.  For example ...

    Neil Lu said:
    6. set breakpoints at the functions that contain EXAMPLE directive;

    This doesn't make sense to me.  The C statement ...

    #define EXAMPLE 10

    ... results in no executable code.  No breakpoint can be set there.  Some later use of EXAMPLE ...

    variable = EXAMPLE;

    does result in executable code, where a breakpoint can be set.  

    With regard to ...

    Neil Lu said:
    but skipped if EXAMPLE is not in the project folder.

    Does it make sense to a take a screen shot of that?  If so, please attach that screen shot to your next post.

    Thanks and regards,

    -George

  • Does it make sense to take the screen shot I requested?  If so, please attach it to your next post.

    Thanks and regards,

    -George

  • Thank you, George, to see your reply on May 24 at E2E, but my mail box received on Fri 5/31/2019 5:23 PM at that moment, every had left for weekend and I don't know why it arrived so late.  Because it was too long, and I almost forget it.  Here is my reply to you:

    "6. set breakpoints at the functions that contain EXAMPLE directive;"

    I mean if you set the breakpoints at the directive and when you run the program in debug mode, it will skip it, but any where, for example, as you created "variable = EXAMPLE;"  will not change 10 if the file is not in the project folder.

    No matter how I express my question, the point is that as I mentioned early to you,  just try any very simple example you like to see you can make it work or not.

    Thank you again,

    • Version of the host OS (Windows 10 64-bit, Service Pack 1)
    • Provide exact version number of CCS (Version 9.0.1.00004)
    • If applicable, exact device/board (TM4C1294) and debug probe used (set to debug)

  • Unfortunately, I am unable to reproduce the behavior you describe.  Please create a small CCS project which has the problem, zip it up as described in the article Sharing Projects, then attach that zip file to your next post.

    Thanks and regards,

    -George

  • Are you able to create the small CCS project I requested?  

    Thanks and regards,

    -George

  • Since it has been a while, I presume you have resolved the problem.  I'd appreciate hearing how you resolved it.

    Thanks and regards,

    -George