Jump to content
  • Advertisement
Sign in to follow this  
Shannon Barber

C++ pedantic, Implicit Declaration

This topic is 4932 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 ) { }

Share this post


Link to post
Share on other sites
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++...

Share this post


Link to post
Share on other sites
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 required
int (*&baz)[5] = bar;


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!