Re: Is section order preserved in C?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 06/16/2010 03:03 AM, David VomLehn wrote:
> This is probably an obscure question, but is the order that C puts things
> in sections with the __attribute((section("secA"))) always the same as
> the order in which they appear in the source file. For example:
> 
> 	void f(void)
> 	{
> 		static int a1 __attribute__((section("A")));
> 		static int b1 __attribute__((section("B")));
> 	}
> 	void g(void)
> 	{
> 		static int a2 __attribute__((section("A")));
> 		static int b2 __attribute__((section("B")));
> 	}
> 
> So, can I count on the storage for a1 being followed by storage for a2 in
> section A and the storage for b1 being followed by storage for b2?
> 
> It makes my life a bit easier if this is true, but I'm rather sure the C
> standard doesn't guarantee it, and wouldn't be surprised if it weren't
> true. I only care about ordering within sections, not the order in which
> sections appear.

No.  Section ordering is controlled by the linker.  If you need some
specific order you can write a link script to do it, but all this is
way outside the subject of gcc.

Andrew.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux