"MaybeExtern" Keyword in C

Status
Not open for further replies.

w_bwr

Member level 3
Joined
Feb 4, 2010
Messages
66
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Karachi, Pakistan
Activity points
1,810
This is a C code for an Embedded application. What does the MaybeExtern implies? It is not given any value.

This Code is written in a Main.c file:
Code:
#define EpanelMain
#include "globals.h"
#undef EpanelMain

This code is written in globals.h .
Code:
#ifdef EpanelMain
    #define MaybeExtern 
#else
    #define MaybeExtern extern
#endif


MaybeExtern _far float fGenCurrent[MaxGeneric], fGenK[MaxGeneric], fGenOff[MaxGeneric], fGenTmp[MaxGeneric];
MaybeExtern _far char cGenNdx, cGenAddr[MaxGeneric], cGenAttr[MaxGeneric], cGenCol[MaxGeneric], cGenDec[MaxGeneric], cGenType[MaxGeneric];
MaybeExtern _far char cGenLbl[MaxGeneric][CPDLabelLen+1], cGenUnit[MaxGeneric][CPDUnitLen];


MaybeExtern _far unsigned char ucGenericNum;
.
.
// Some More Variables
.
.
#undef MaybeExtern
 

If you think about it. The macro checking the EpanelMain is making that code to define local or extern variables.
Code:
#ifdef EpanelMain  //If EpanelMain is defined
    #define MaybeExtern  //Then the "boolean" MaybeExtern will be defined as nothing
#else
    #define MaybeExtern extern  //Else define MaybeExtern as extern
#endif

So this is a "game" of declare/define depending on EpanelMain.
 

 

The Macro name does show any arguments. Is this Macro Syntax?

Actually, the technical term is preprocessor/compiler directives and are used to "prep" the source before the actual process of compiling.

Essentially, any valid keyword preceded by the "#" symbol is a preprocessor/compiler directive, including predefined macros, includes, etc.


BigDog
 

Preprocessor Driective are commonly used for three purporses:
1: Header Filer like this
Code:
#include <stdio.h>

2: Macro
Code:
#define [Function Name with arguments]    [condition]
#define Max(int a, int b)  (a>b) ? a :b

3: Defining Constants
Code:
#include [Name]  [Constant Value]
#include T4_Trap 0x27

But what does this means:
Code:
#ifdef EpanelMain
    #define MaybeExtern 
#else
    #define MaybeExtern extern
#endif

EPanel is defined in the main file. so the "if" condition true.
Code:
#define MaybeExtern

What is it exactly _ a Macro or boolean constant as pedroromanvr mentioned? It doesn't show any arguments neither show a constant value.
 

bigdogguru is correct, the proper term is compiler or preprocessor directives.
In this case
Code:
#if
#ifdef
#ifndef
#else
#elif
#endif
Those are directives that can be used for conditional compilation. So basically in
Code:
#ifdef EpanelMain
    #define MaybeExtern 
#else
    #define MaybeExtern extern
#endif
You are asking, is EpanelMain defined?, if not all variables will be declared as extern in compilation time.
 


If EpanelMain is defined then the resulting code equals

Code:
_far float fGenCurrent[MaxGeneric], fGenK[MaxGeneric], fGenOff[MaxGeneric], fGenTmp[MaxGeneric];
_far char cGenNdx, cGenAddr[MaxGeneric], cGenAttr[MaxGeneric], cGenCol[MaxGeneric], cGenDec[MaxGeneric], cGenType[MaxGeneric];
_far char cGenLbl[MaxGeneric][CPDLabelLen+1], cGenUnit[MaxGeneric][CPDUnitLen];

If EpanelMain is not defined then the code results to

Code:
extern _far float fGenCurrent[MaxGeneric], fGenK[MaxGeneric], fGenOff[MaxGeneric], fGenTmp[MaxGeneric];
extern _far char cGenNdx, cGenAddr[MaxGeneric], cGenAttr[MaxGeneric], cGenCol[MaxGeneric], cGenDec[MaxGeneric], cGenType[MaxGeneric];
extern _far char cGenLbl[MaxGeneric][CPDLabelLen+1], cGenUnit[MaxGeneric][CPDUnitLen];
 
Reactions: w_bwr

    w_bwr

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…