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.

Defining a Union at a perticular address in C

Status
Not open for further replies.

nrmlguru

Newbie level 4
Newbie level 4
Joined
Jan 25, 2009
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,310
Hello,

Please help me to define a Union at particular address.

say at address 0x1234
 

you declare the union, define a pointer to the type and initialise it with the address
Code:
typedef	union
{
	unsigned long int value;
	char xch[2];
} TempData;

TempData *ptr= (TempData* )0x1234;
what happens if you use the pointer to access the object pointed to depends on the system you are using and if the pointer holds a valid address, e.g.
Code:
ptr->value=1;
if the pointer does not hold a valid address you could get an exception, address error, segmentation error, etc or it may appear to work corrupting memory contents and possibly causing a crash later.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top