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.

TMS320F28379D: Usage of extern C neglects the content of header file

Part Number: TMS320F28379D


Hi, 

I have the x.h, which runs well with the GCC compiler. but gives an error with the C compiler. The error is the below thread. https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1106808/tms320f28379d-shift-count-is-too-large/4103321?tisearch=e2e-sitesearch&keymatch=%20user%3A484362#4103321 

I tried to solve this as 

// in Y.h  \\ header file

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include "x.h"
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
 but it is ignoring the content of x.h file. 

So, 1. Is there any other way than to modify the x.h to remove the errors of the thread shown above ?

2. is __cplusplus not known by CCS ?

3. how can I tell the compiler to make unsigned int as 32 bit wide instead of 16 bit ? is it even possible ?

I am using CCS10 and v20.2.2.LTS compiler. 

Thanking you. 

VP

  • VP,

    Our compiler expert is out so I will do my best to respond.

    #1 why are there 2 #ifdef __cplusplus in this file?

    Here I include test.h from my main c file.  This has the first #ifdef __cplusplus from your file but not the second one which I did not see a purpose for.  In my example test.h includes john.h which just defines a global variable.  I can build this and the global variable is present.

    2. is __cplusplus not known by CCS ?

    I believe there is a bug in the CCS editor where it thinks __cplusplus is defined as it is always present when using GCC.  __cplusplus is not present when using the TI C2000 compiler.  You could define it yourself in the predefined symbols.

    Here I tweaked the above example to include a mary.h with a different variable if __cplusplus is defined

    Another way to show this is:

    #ifdef __cplusplus
        #include "mary.h"
    #else
        #warn("__cplusplus is not defined");
    #endif /* __cplusplus */

    When I build I will see:

    "../test.h", line 18: warning #1181-D: #warning directive: ("__cplusplus is not defined");

    3. how can I tell the compiler to make unsigned int as 32 bit wide instead of 16 bit ? is it even possible ?

    int is 16bits on C2000 devices.  

    You can use uint32_t

    Regards,

    John

  • Hi John, thank you for your answers. 

    I understand now. So, I tried to treat only one variable of the x.h file as 32 bit wide and then the inclusion of x.h, but seems the compiler is skipping all the header file content, is it because of the compiler bug?

      

    #ifdef __cplusplus
    extern 'C' unsigned long ANYVARIBALE; // this is used and declared in x.h 
    #include "x.h"
    #endif

    Since GCC compiler is defining 'ANYVARIABLE ' as 64-bit, while C2000 as 16 bit, what could be another way to tell the compiler that for only that variable it has to define as 64 bit and the rest of others as it is. 

    Because the main problem is I cannot modify the x.h file, otherwise In the header itself I would have defined it for that particular variable. 

    Thanking you 

    VP

  • VP,

    I am not sure what you are referring to as a compiler bug.  Here I have taken your original source from the first post.  The only thing I changed was to change x.h to john.h.  As you can see john.h is included as the variable it defines is present.  That is correct as the #include is outside of the conditional blocks.

    If I do it like the last post

    Then it will fail to build as john.h is not included as __cplusplus is not defined and my code references the variable.  This is also correct.

    The compiler is behaving correctly.

    If you need to tell if the code is being built for a TI C2000 device you could either define a symbol in your build options and set it based on what you are building for.

    Another option would be to look for one of the predefined symbols that the TI compiler always has such as __TI_COMPILER_VERSION__

    In the above capture, I look for that symbol and if it is present I include john.h.  If it is not I include mary.h.

    Since GCC compiler is defining 'ANYVARIABLE ' as 64-bit, while C2000 as 16 bit, what could be another way to tell the compiler that for only that variable it has to define as 64 bit and the rest of others as it is. 

    Because the main problem is I cannot modify the x.h file, otherwise In the header itself I would have defined it for that particular variable. 

    Is ANYVARIABLE 64bit or 32bit?  Regardless the question is the same.  Our compiler expert is out until mid next week but this is really a generic question related to getting code to run on a C2000 device.  I will see if the C2000 team can help.

    Regards,

    John

  • how can I tell the compiler to make unsigned int as 32 bit wide instead of 16 bit ?

    The include file <stdint.h> contains portable types to get fixed width integers. E.g. the type uint32_t is for a 32-bit unsigned integer.

  • Hello, 

    I think it is not a clear explanation from my side. The main problem is john.h is a file with c++ syntax. But I would like to use it in the C compiler, without modifying the john.h. 

    I believe there is a bug in the CCS editor where it thinks __cplusplus is defined as it is always present when using GCC.  __cplusplus is not present when using the TI C2000 compiler.  You could define it yourself in the predefined symbols.

    If I define__cplusplus in the C compiler then I have around 600 errors since other files are in C format. 

    When I build I will see:

    "../test.h", line 18: warning #1181-D: #warning directive: ("__cplusplus is not defined");

    Even I see the same warning. So, at this point what could be the solution to tell the compiler that a specific variable size is 32 bit, without modifying john.h, since this variable is in john.h, as well as I would like to include the john.h in the my C compiler. 

    I hope it is clear now. 

    Thanks, and regards, 

    VP

  • VP,

    We are looking into solutions to your issue.  Please give us a few days to get the right folks looped in.

    Best,

    Matthew

  • hello,

    Can I use pre-build steps to define a variable of the c++ header file which is giving me an error? but did not find a post if one can declare a variable/s in prebuild steps. Is it possible? 

    I am trying to have the workaround of adding c++ header files in a C header, using a C compiler, which is the main issue.  

    Vidhi

  • Vidhi,

    We will need to ask for another day or 2 of time to come up with the response, there are some team members that are Out of the office currently that we need to comment.

    Best,

    Matthew

  • I am responding to questions you pose in the first post in this thread.

    1. Is there any other way than to modify the x.h to remove the errors of the thread shown above ?

    I suspect the answer is no.  I suspect the code in x.h presumes the built-in type int is 32-bits wide.  On C28x, the built-in type int is 16-bits wide.  Building the code as C++ has no effect on this difference.

    2. is __cplusplus not known by CCS ?

    C++ is supported by the C28x compiler.

    how can I tell the compiler to make unsigned int as 32 bit wide instead of 16 bit ? is it even possible ?

    It isn't possible.

    Thanks and regards,

    -George

  • Hello George, 

    So, How can I move forward? there has to be some workaround in my opinion. What do you think ?

    Thanking you, 

    Vidhi

  • If code in the header file presumes the built-in type int is 32-bits wide, then the only way forward is to change the header file.  The typical solution is to #include <stdint.h> and use the type int32_t where needed.

    Thanks and regards,

    -George

  • Hi George, 

    I tried changing the unsigned to 32-bit in #include <stdint.h>  but then I have other errors. I was thinking If I can define that particular variable as 32-bit in pre-build steps. is it possible ?

    Thanking you!

  • It is probably not possible.  But I'm not sure what you mean by ...

    If I can define that particular variable as 32-bit in pre-build steps.

    Please give a detailed example that shows how this could work.

    Thanks and regards,

    -George

  • George, 

    Even I think it is not possible, I wanted to ask if there can be a solution like this because I was thinking if I can have some kind of workaround. maybe some .py/.cpp file in which I can change the datatype run it before the compilation and then maybe I can exclude the c++ header file from the compilation. 

    Or

    maybe using some pragma defined in the c header file??

    These are just my thoughts on making it work. 

    Thank you 

    Vidhi

  • I do not have clear understanding of what you propose to do.  Even so, I continue to think it is not possible.

    Thanks and regards,

    -George

  • Hi George, thank you for the patience. So to understand the discussion and close it also. the problem is: that the inclusion of the C++ header file in the C header with CCS10 using the C compiler is not possible?

    Vidhi