type casting
N V Krishna
nvk@cs.purdue.edu
Thu Jan 10 10:24:00 GMT 2002
Hi,
I have the following C code :
main(){
int *p;
p=p+(unsigned int)p;
}
When I am inspecting the AST using debug_tree, the following is shown :
I am just printing the tree for the plus_expr :
-------
arg 1 <plus_expr 0x401c0500 type <pointer_type 0x401bf9c0>
arg 0 <var_decl 0x401c8dd0 p>
arg 1 <convert_expr 0x401bde74 type <pointer_type 0x401bf9c0>
arg 0 <mult_expr 0x401c04a0 type <integer_type 0x401bc340 unsigned int>
arg 0 <nop_expr 0x401bde24 type <integer_type 0x401bc340 unsigned int>
arg 0 <convert_expr 0x401bde10 type <integer_type 0x401bc2d8 int>
arg 0 <var_decl 0x401c8dd0 p>>>
arg 1 <integer_cst 0x401c0480 constant 4>>>>>
------
My question is regarding the first convert_expr. If I translate it then it
means :
(int *)(p + (int *)(((unsigned int)(int)p)*4))
// NOTE : On my machine sizeof(int) = 4.
If we omit some of the obvious casts :
p + (int *)((unsigned int )p * 4)
But gcc does not allow addition of two pointers. Is it an incorrect
representation of C code or I am missing something?
One more question is that, it seems incorrect to translate
(unsigned int)p
to
(unsigned int)(int)p ?
I feel so; unless, again I am missing something.
I am trying to write a unparser for gcc's AST. Given a
function/statement/expression node, the unparser will print the C code for
that. This could be helpful for people working on different
transformations on the trees.
Warm regards
Krishna
--
Key fingerprint = FBA9 8F1D D026 74DC 8D47 4A6D 1009 1D68 BBF9 31A8
---
Homepage:http://www.cs.purdue.edu/homes/nvk
More information about the Gcc
mailing list