« first day (261 days earlier)      last day (2588 days later) » 

4:34 PM
Anyone knows why the struct variable from an array of structs points to something different than directly accessing it with an index?

e.g. list[0].x = 3; works but struct Test name = list[0]; name.x = 3; doesnt?
 
nwp
the problem is that name is a copy of list[0] and you change the copy, but not list[0]
to fix that use Test &name = list[0]; to make name an alias for list[0] so you don't make a copy and change the original
 
or make name a pointer: Test *name = &list[0];name->x = 3;
 
thanks
 
 
5 hours later…
9:32 PM
today i met such a statement 'extern int = 0 ;' in global scope. and i do not know what it is intended for, unfortunately. is it legal somewhere.?
 
nwp
extern int i = 0; is legal and makes sense, apparently the identifier is optional, which as far as I can tell makes it completely useless. I would have to dig through the standard to see if it is legal or ill-formed, but since it doesn't do anything I don't think it is worth it.
 
well, it does not compile, so i assume that it has to be a non-standard feature.
 
@GreenTree It's legal and meaningful in C. Assuming it's outside any function, it's equivalent to just int i = 0;. The extern just explicitly states the storage class, which would be extern by default anyway.
 
nwp
I can't get it to compile, neither for C nor C++, not even with VS
maybe it compiled under some older compiler
 
9:48 PM
Then you're doing something wrong. It should definitely compile as C, even with a current compiler. The C11 standard gives the example:
extern int i3 = 3; // definition, external linkage
(§6.9.2/4).
 
nwp
@JerryCoffin but the identifier is missing in the example in question
 
@nwp Oops--I looked at your extern int i = 0; and didn't notice the preceding one with no i in it. Yeah, that should be rejected by any properly functioning compiler--it's just broken syntax.
 
nwp
I suppose it compiles under brainfuck but that probably doesn't count.
 
@nwp Well, yes; I did mean a compiler for C or C++ (or something at least vaguely similar).
Under brainfuck it would be accepted, but wouldn't actually compile--it's strictly a comment.
 

« first day (261 days earlier)      last day (2588 days later) »