🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #4866

alignment requirements for all structures?

#4866
From: Wil Evers
Date: Thu, 07 Mar 1996 15:12
43 lines
1385 bytes
Hi!

I have a few questions for the ANSI/ISO C gurus:

(1). Is there a rule in the C standard stating that the address of *every*  
structure - irrespective of its contents - should satisfy some alignment  
requirement? For example, is the following guaranteed to work?

	struct a { char data[sizeof(double)]; } ana;
	struct b { double data; };

	int main()
	{
		((struct b *) &ana)->data = 42.42;
		return 0;
	}

(2). If the answer to (1) is no, then is a conforming compiler allowed to  
assign some specific alignment requirement to a data type, just because it  
is defined as a structure, and again irrespective of the contents of the  
structure? For example, if I write:
	
	#include <stdio.h>

	struct c { char data; } carray[10];

	int main()
	{
		printf("%u\n", sizeof carray);
		return 0;
	}

would it be legal for this program to print something other than 10?

(3). If the answer to (2) is yes, why would a compiler want to do this?

Thanks in advance,

- Wil

Wil Evers, <wil@ittpub.nl>
ITT Publitec Research and Development BV, Amsterdam, Holland
  
Technical Details
Message-ID: <1996Mar7.151216.1793@ittpub>
Path: arc1-ca.pugleaf.net!surfnet.nl!sun4nl!ittpub!ittpub!nntp

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!surfnet.nl!sun4nl!ittpub!ittpub!nntp
Newsgroups: comp.std.c
Subject: alignment requirements for all structures?
Message-ID: <1996Mar7.151216.1793@ittpub>
From: wil@ittpub.nl (Wil Evers)
Date: 7 Mar 96 15:12:16 WET
Distribution: world
Nntp-Posting-Host: lintilla