C++ pedantic, Implicit Declaration

Started by
9 comments, last by mgarriss 18 years, 10 months ago
True or False: An object if defined, need not be declared. New question: I can't figure this one out. Is there anything you can initialize this refernece to? int (*&r5)[5] = ?; [Edited by - Magmai Kai Holmlor on June 8, 2005 10:13:59 PM]
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Advertisement
...true?

I am by no means sure
I absolutely believe a definition also acts as a declaration. I don't have my C++ Standard here, unfortunately. Great, now I'll lose sleep over trying to find a counter-example.

Curse you, MKH.

Edit - a nameless struct type might be considered a borderline case: struct { int i; } foo;. It does declare and define a variable, also defines a type, but it could be argued that the type itself is not really declared... Idem for nameless temporaries. I don't know what the standard says though.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
True -- isn't this the definition of Implicit Declaration?
Things change.
False? You don't mention that it's defined before it's used, whereas declaration kind of implies that the declaration is before it's used.
Good enough, what I really wanted to know is that the answer was too ambiguous to answer without a Standard witch-hunt.

I also thought it was an implicit declaration, so the question becomes does the definition count as a declaration thus the answer is false, or is it true because it's not declared elsewhere.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
false.

i think clause 3, section 1, para 2 indicates this (3.1 -2- )...

http://www.kuzbass.ru:8086/docs/isocpp/basic.html#basic.def

basically any definition is also a declaration. this is fine because there can be many declarations. for example the following is well-formed...
void foo ( int );void foo ( int );void foo ( int );void foo ( int ) { }
Quote:Original post by Magmai Kai Holmlor
New question:
I can't figure this one out. Is there anything you can initialize this refernece to?
int (*&r5)[5] = ?;


GCC allows one to initialize it to itself...:

int (*&r5)[5] = r5;

Of course this will have undefined behavior and might not be ISO C++...
Quote:New question:
I can't figure this one out. Is there anything you can initialize this refernece to?
int (*&r5)[5] = ?;


Well, it is a reference to a pointer to an array of 5 int, so it should be well-formed to initialize it with a pointer to an array of 5 ints. The latter, in turn, can be initialized with an address of such an array:

int foo[5];int (*bar)[5] = &foo  // note the address-of operator is requiredint (*&baz)[5] = bar;


You are one sick dude, Magmai.

This topic is closed to new replies.

Advertisement