Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

"MaybeExtern" Keyword in C

Status
Not open for further replies.

w_bwr

Member level 3
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.
 

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.
.[/QUOTE]

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

If EpanelMain is set. This makes this "MaybeExtern _far float fGenCurrent[MaxGeneric]" variable only this "_far float fGenCurrent[MaxGeneric]".
 

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];
 
  • Like
Reactions: w_bwr

    w_bwr

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top