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.

what is mean by const struct?

Status
Not open for further replies.

smartshashi

Member level 4
Joined
Aug 11, 2004
Messages
68
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
513
Hi all,

If I am declaring structure as below

struct StructTemp
{
int a;
};

const struct StructTemp Var1;

So what is meaning of const here? Does it mean Address of Var1 is constant or or members of Var1 (a) is constant??
Please help.
 

Do you see addresses involved in the code (e.g. by defining a pointer)? The const storage class is usually implemented in program flash, this means that all structure members are constants defined at compile time. Depending on the processor memory architecture, a separate pointer type may be needed to access the constant data elements.
 

^^^right
and just to be clear, the const here tells the compiler the variable var1 and its members are constant at compile time. That means will be at a fixed location in memory.

you may be confused with use of const pointer though?

struct _struckTemp
{int a;
};

struct _struckTemp Var1[10];

const struct _struckTemp *pvar;

pvar = &Var1;

*pvar->a = 10; !!!fail - illegal
pvar++; !!!ok - increment pointer to next element
!!!so the value in pvar which is an address can change, but what it points to is a constant.
if(pvar->a == 0) !!!ok
 

    V

    Points: 2
    Helpful Answer Positive Rating
struct is just a type here, just as int.

So if you understand the semantics of

const int c_i;

then you should not have any difficulty in understanding

const struct any_struct_type c_s;

Hope that helps.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top