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.

Explain me two statements in C

Status
Not open for further replies.

london

Member level 4
Joined
Jun 30, 2006
Messages
79
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,945
statement 1

*(unsigned int *)0x1000 = 0x0000;

statement 2

char *pLCD = (char *)&LCDM1
*pLCD=0x00;
 

Re: can u explain me!!!

statement 1

*(unsigned int *)0x1000 = 0x0000;

statement 2

char *pLCD = (char *)&LCDM1
*pLCD=0x00;


statement-1
------------------
the address location 0x1000 is typecasted to fit a Unsigned integer, and then the value at that location is
being set to 0x0000.
it is similar to the following statements:
int *p;
p=(unsigned int *)0x1000;
*p=0x0000.

statement-2
-----------------
LCDM1 might be # defined to a particular address location / beind assinged with a value of an address
in these statements we are type casting it to a character pointer (dereferencing the pointer)
and assingning the ascii value 0 to it.
since p is a character pointer, any statement like
char a=*p;
will result in "NULL" being assinged to a.

Please dont forget the HELPED ME button.
 

    london

    Points: 2
    Helpful Answer Positive Rating
Re: can u explain me!!!

ivar4ever said:
statement 1

*(unsigned int *)0x1000 = 0x0000;

statement 2

char *pLCD = (char *)&LCDM1
*pLCD=0x00;


statement-1
------------------
the address location 0x1000 is typecasted to fit a Unsigned integer, and then the value at that location is
being set to 0x0000.
it is similar to the following statements:
int *p;
p=(unsigned int *)0x1000;
*p=0x0000.

statement-2
-----------------
LCDM1 might be # defined to a particular address location / beind assinged with a value of an address
in these statements we are type casting it to a character pointer (dereferencing the pointer)
and assingning the ascii value 0 to it.
since p is a character pointer, any statement like
char a=*p;
will result in "NULL" being assinged to a.

Please dont forget the HELPED ME button.


is it possible to apply same procedure of statement2 to statement1? if so pls explain me with same code
 

Re: can u explain me!!!

there is a mistake in my what i have written.
the explanation for the second statement should Like:
LCDM1 is a variable, it is not an address location. the address of this variable is being dereferenced.
sorry for that, and similarly if you want to implement the statement-1 like statement-2 :
let us supposr LCDM1 is replaced by a varialbe ABC
but this variable needs to be at the location 0x1000
and i dont know how to place a variable at a particular address location(using C), since the address will be
allocated by the compiler.
i think we can do it through assembly instrucitons. will refer and get back to you.
 

Re: can u explain me!!!

ivar4ever said:
and i dont know how to place a variable at a particular address location(using C), since the address will be allocated by the compiler.
i think we can do it through assembly instrucitons. will refer and get back to you.
It depends on what C compiler you are using. Some C compilers for PIC, such as Hi-Tech PIC C or BKND's CC5X can do that for you. I'm sure there are other C compilers for other families can do that as well.

Cheers,
 

Re: can u explain me!!!

yes that is true, but is there any way to implement it in the language itself, so that we need not depend on the compiler?
and through Assembly also, as far as i could get, we can store a VALUE at a particular location,but we cannt access it using a VARIABLE name.
if anybody know how to do it , please help.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top