Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gcc and using constants in array declarations



2004-05-26 kl. 08.44 skrev Andrew White:

In gcc 3.3, the following code produces an error:

const int k_my_array_size = 3;
const int g_my_array [k_my_array_size] = { 1,2,3 };

file:line: error: variable-size type declared outside of any function
file:line: error: variable-sized object may not be initialized

This is a legal (and recommended) C++ construction. Is there a way to convince gcc to allow it in C, or do I just give up and use a #define?

All I can say is I had the same problem and ended up using #define. Doesn't mean there's not a way past it, just that I couldn't find one. What you could do however is the opposite way:

const int g_my_array [] = { 1, 2, 3 };
const int k_my_array_size = sizeof (g_my_array) / sizeof (*g_my_array);
--
Pelle Johansson
<email@hidden>
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.


References: 
 >gcc and using constants in array declarations (From: Andrew White <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.