Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > How to parse ?

Reply
Thread Tools

How to parse ?

 
 
junky_fellow@yahoo.co.in
Guest
Posts: n/a
 
      06-21-2005
How the following expression is parsed ?

*(int *)&flag;

What are the general steps that should be followed in interpreting
such expressions ?

Thanx for any help ...

 
Reply With Quote
 
 
 
 
Zoran Cutura
Guest
Posts: n/a
 
      06-21-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> How the following expression is parsed ?
>
> *(int *)&flag;
>
> What are the general steps that should be followed in interpreting
> such expressions ?


The precedence and associativity rules of the operators can be taken
from most text books. For example K&R2s table 2-1 list them.

You take a look at the operators and find out in which order they are to
be evaluated. In your example above (which may result in undefined
behavior and doesn't have have real live meaning at all) the "*", "()"
and "&" operator all have the same precedence but are to be evaluated
right to left according to K&R2 so it goes like.

Get the address of flag, let that address be a pointer to an int and
take the content of that int.

--
Z ((E-Mail Removed))
"LISP is worth learning for the profound enlightenment experience
you will have when you finally get it; that experience will make you
a better programmer for the rest of your days." -- Eric S. Raymond
 
Reply With Quote
 
 
 
 
john_bode@my-deja.com
Guest
Posts: n/a
 
      06-21-2005


(E-Mail Removed) wrote:
> How the following expression is parsed ?
>
> *(int *)&flag;
>


1. flag -- start with the identifier; in this case, flag
2. &flag -- get the address of flag
3. (int *)&flag -- convert the type of &flag from pointer to T
(whatever flag's base type is) to pointer to int
4. *(int *)&flag -- dereference the address of flag as though it were
a pointer to int.

Basically, you're intepreting the bit pattern stored in flag as though
it were an integer. Note this may or may not give a meaningful or
useful result depending on the base type of flag.

> What are the general steps that should be followed in interpreting
> such expressions ?
>


Read up on dereferences and cast expressions in your handy C reference
manual.

> Thanx for any help ...


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
optparse: parse v. parse! ?? 7stud -- Ruby 3 02-20-2008 05:20 AM
How to parse a string like C program parse the command line string? linzhenhua1205@163.com C Programming 19 03-15-2005 07:41 PM
Parse an xml file with line breaks in the beginning Raj Mudaliar Perl 0 07-14-2003 06:00 PM
[TABLE NOT SHOWN] problem with HTML::Parse Mitchua Perl 3 07-13-2003 11:38 PM



Advertisments