Re: static / extern fails in GCC 4
Re: static / extern fails in GCC 4
- Subject: Re: static / extern fails in GCC 4
- From: Dirk Stegemann <email@hidden>
- Date: Fri, 2 Dec 2005 00:51:28 +0200
Hi,
Am 01.12.2005 um 15:23 schrieb Cameron Hayne:
On 1-Dec-05, at 8:00 AM, Dirk Stegemann wrote:
extern const int kBuffer[3];
static const int kBuffer[3] = {1, 2, 3};
int main (int argc, char * const argv[]) {
// insert code here...
return 0;
}
How about just removing the 'extern' declaration?
I'm not sure why you put it there in the first place.
Actually, in the *real* source file, there's some more code between
the "extern ..." and the "static ..." statements, which uses the
declared constant. Because 'kBuffer' can be *very* huge, debuggers
stop debugging such code properly. Putting the huge, debug-preventing
'kBuffer' definition at the end of the source file somehow "solves"
this issue, and the "extern ..." statement allows the code written
above of those definitions to still use the const buffer.
An 'extern' declaration of a variable is used when you want to
refer to a global variable that "lives" in some other source file.
I always thought the 'extern' declaration to exist for exactly this
purpose, and was quite amazed to see it fulfill the job I described
above... as often, this code is written (actually, generated) on
Win32, where compilers don't complain about it :-/
But with the 'static' in front of the line that defines that
variable, it is not a global variable - it is a file scope variable
(it cannot be accessed outside of the file where it is defined).
Aha!
Having the 'static' there should not affect performance at all. I
think you are getting confused with an unrelated use of 'static'
with variables declared inside a block (e.g. inside a function).
Precisely... :o)
Now I suggested to put the const buffer into a dedicated namespace,
so the "static' declaration -- which in fact was intended to
*prevent* the buffer from appearing in global scope -- can be removed
at all, which allows the "extern" to stay as it is. The developer
group responsible for this code will evaluate this solution, but I
guess it should solve the problem...
Thanks for your input!
Regards,
Dirk Stegemann
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden