Why does the C18 compiler define __18CXX for a 18f27j53

AlexR

Joined Jan 16, 2008
732
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.
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
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.
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.
 

AlexR

Joined Jan 16, 2008
732
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.
 

hexreader

Joined Apr 16, 2011
581
From the C compiler help menu:

Predefined Macro Names
In addition to the standard predefined macro names, MPLAB C18 provides the following predefined macros:

__18CXX The constant 1, intended to indicate the MPLAB C18 compiler.

__PROCESSOR The constant 1 if compiled for the particular processor. For example, __18C452 would be defined as the constant 1 if compiled with the -p18c452 command-line option and __18F258 would be defined as the constant 1 if compiled with the -p18f258 command-line option.

__SMALL__ The constant 1 if compiled with the -ms command-line option.

__LARGE__ The constant 1 if compiled with the -ml command-line option.

__TRADITIONAL18__ The constant 1 if the Non-Extended mode is being used
(see Selecting the Mode).

__EXTENDED18__ The constant 1 if the Extended mode is being used
(see Selecting the Mode).
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:
Top