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.

#include "IQmathLib.h" in header file

Other Parts Discussed in Thread: TEST2

I program for a C2000 microcontroller. Every time when I create a structure type including members of IQ data type in the header file, I have to include the "IQmathLib.h", or the compiler would show errors. Is there anyway so that I don't have to write '#include "IQmathLib.h"' in each header file?

#ifndef __TEST_H__

#define __TEST_H__

#include "IQmathLib.h"

typedef struct

{

    _iq test1;

    _iq test2;

} TEST;

......

  • At the end of the day, IQmath.h needs to somehow get in to each source file using IQmath.  You could include IQmath.h in some other header file that you already have included in each source file using IQmath.

    Regards,

    David

  • David M. Alter said:

    At the end of the day, IQmath.h needs to somehow get in to each source file using IQmath.  You could include IQmath.h in some other header file that you already have included in each source file using IQmath.

    Regards,

    David

    David:

    Thank you very much for your reply.

    But it seem that I need to include IQmath.h in each header file where structure including IQ type variables is defined.

    If I do it like this, without including IQmath.h:

    #ifndef __TEST_H__

    #define __TEST_H__

    typedef struct

    {

        _iq test1;

        _iq test2;

    } TEST;

    The code is not able to be compiled successfully because I use '_iq' in the structure definition. Is there any way to make it simple so that I don't need to include IQmath.lib in this kind of header file? I saw some code in which the header file does not include IQmath.lib or anything else while the structure variables are defined with _iq successfully. I don't know what is wrong in my code or the compiler. 

    Fan

  • This is basic 'C' stuff - it has nothing specifically to do with IQMath or CCS.

    Fanx said:
    Is there any way to make it simple (sic?) so that I don't need to include IQmath.lib in this kind of header file?

    As  has already said, you just need to make sure that you #include "IQmathLib.h" some time before you use anything else which requires it - including  #include-ing headers which require it:

    :
    :

    #include "IQmathLib.h" /* This makes the IQMath stuff available to everything which follows... */

    :
    :

    #include "test,h"  /* A header which requires IQMath */

    #include "test2,h"  /* Another header which requires IQMath */

    /* A local use of IQMath */
    typedef struct
    {
        _iq test1;
        _iq test2;
    } TEST;

    :
    :
    etc...

    Whether this is actually any "simpler" is debatable - because you now have to worry about taking care to get your #includes in the right order...!

    Fanx said:
    I don't know what is wrong in my code or the compiler. 

    It's your code, I'm afraid - see above.

     

  • Andy Neil said:

    This is basic 'C' stuff - it has nothing specifically to do with IQMath or CCS.

     

    http://c-faq.com/cpp/nestincl.html

     

     

  • Fanx,

    Fanx said:

    I saw some code in which the header file does not include IQmath.lib or anything else while the structure variables are defined with _iq successfully.

    Not possible.  The code you saw must have had IQmath.h included somewhere upstream of the use of _iq.  As Andy said, this is basic C stuff and has nothing to do with IQmath or the C2000 compiler.

    What you could do is create a master include file that you include in all your C-source files.  That include file will include all the other include files (and I usually put all constant definitions, variable externs, function prototypes, etc. in here).  As Andy said, you will need to include IQmath.h BEFORE any other include file that references an IQ symbol (such as _iq).  But at least this way once you get the order of the include files correct, you can forget about it (until someone else comes along and modifies the file and breaks the code!).  A downside of this approach is that a change to ANY include file will cause your entire project to rebuild on an incremental build.  Some people do not like this because very large projects will take time to rebuild.

    - David

  • David M. Alter said:
    a master include file that you include in all your C-source files.  That include file will include all the other include files (and I usually put all constant definitions, variable externs, function prototypes, etc. in here) ...   Some people do not like this because very large projects will take time to rebuild.

    And some people would call this "poor style" - as it breaks with the principles of modularity and loose coupling.

    But that's a whole different discussion (again, nothing specifically to do with IQMath, CCS, or TI)...

  • David, Andy:

    Thank you very much!

    I got it!

    Fan