Hiding Names

Hiding Names - "xxx", and the...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Hiding Names Consider this small example: #include <stdio.h> int xxx[10]; int main() { struct xxx { int a; }; printf("%d\n", sizeof(xxx)); return 0; } When compiled as C code, it will typically print a value like 20 or 40, whereas when treated as C++, the output value will likely be 2 or 4. Why is this? In C++, the introduction of the local struct declaration hides the global
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: &quot;xxx&quot;, and the program is simply taking the size of a struct which has a single integer member in it. In C, &quot;sizeof(xxx)&quot; refers to the global array, and a tag like &quot;xxx&quot; doesn't automatically refer to a struct. If we said &quot;sizeof(struct xxx)&quot; then we would be able to refer to the local struct declaration....
View Full Document

Ask a homework question - tutors are online