Why does the C18 compiler define __18CXX for a 18f27j53

Discussion in 'Embedded Systems and Microcontrollers' started by spinnaker, Jan 1, 2012.

  1. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,887
    1,019
    Why is the C18 compiler defining __18CXX for a 18f27j53 PIC?
     
  2. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    If you include the __18CXX in your source file instead including the header file for the device you are using, the C18 compiler will pick up whatever header file matches the device type as selected by the IDE "Configure/Select Device..." setting.
    That way simply changing the device type in the IDE setting will automatically change the header file that gets used by the compiler.
     
  3. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,887
    1,019
    But I have the p18f27j53.h include file in the source and I am the Configure/Select Device set to 18f27j53.

    It does not seem to matter what 18F device I use __18CXX is always defined.
     
  4. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    If the __18CXX file is included then you don't need to include the 18f27j53 file. As long as you set the correct device type in the IDE the __18CXX will pick up the correct header file for you.
    Have a read though the __18CXX.h file and you will see what I mean.
     
  5. hexreader

    Active Member

    Apr 16, 2011
    250
    82
    From the C compiler help menu:

    The compiler defines this macro name to indicate that C18 compiler is in use. I seem to remember that this is used by many libraries and user code to cater for different options with the same code.

    For instance - if __18CXX defined, do a PIC18-type thing, else do a PIC16-type thing.

    Or maybe - if __18CXX defined, do something using C18 syntax, else do the same thing using Hi-Tech C syntax.

    In other words - this allows for conditional compiling.

    Hope this helps.
     
    Last edited: Jan 2, 2012
    stahta01 likes this.
Loading...