tags:

views:

38

answers:

1

Is it possible to lookup where a typedef is being defined?

I am running into this very evasive problem that is producing the following compiler error:

/usr/include/stdint.h: At global scope:
/usr/include/stdint.h:57: error: duplicate 'unsigned'
/usr/include/stdint.h:57: error: declaration does not declare anything

where /usr/include/stdint.h:57 is:

typedef unsigned int uint32_t

My initial thoughts are that something else is defining uint32_t, and when stdint tries to re-define it, the error is thrown. But I don't know how I can trace back to where this typedef was called, or even what the current value of uint32_t is when this is called.

Any ideas?

+1  A: 

You can get the preprocessed output (-E on most compilers) which will give you the complete declarations of all the headers. Within that you can grep for uint32_t. That should show which header was the one which caused the duplicate typedef.

Gangadhar
Thanks, it looks like that gave me what i would have needed (had I not just discovered the root cause a few minutes before reading this). I went as far as constructing an #include tree just before the error to see if something else was typedef'ing it beforehand. Unfortunately, i was so engrossed with typedef, i neglected to look for #defines. In a recent branch merge, someone had #defined uint32_t to unsigned long, so in stdint.h (called after the #def) the line: 'typedef unsigned int uint32_t' was actually 'typedef unsigned int unsigned long', hense the duplicate 'unsigned' and my problems.
Paul
That was something I forgot to add in my answer - watch out for #defines and that is where -E helps.
Gangadhar