Re: struct compatibility
- From: Marc Boyer <Marc.Boyer@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 31 Jan 2006 09:54:04 +0000 (UTC)
Le 31-01-2006, Christian Kandeler <christian.kandeler@xxxxxx> a écrit :
> Hi,
>
> I'd like to know whether the following code is standard-compliant:
>
>
> struct generic {
> int x;
> int a[1];
> };
>
>
> void f(struct generic *s)
> {
> int i;
>
> for (i = 0; i < 10; i++)
> s->a[i] = i;
> }
>
>
> int main(void)
> {
> struct special {
> int x;
> int a[10];
> } s;
>
> f((struct generic *) &s);
>
> return 0;
> }
Interesting question...
If s was allocated on the heap, in C99, I think the code
would be standart because of compatibility with flexible
array member.
The standart says that, 6.7.2.1/16-18, if there exist
struct s {
int x;
int a[]; // No size !
};
Then, generic and s are 'compatible' when allocated
with malloc, and also are special and s.
In your example, there is no s, but I do not think
it will create any difference for compilers.
Marc Boyer
.
- References:
- struct compatibility
- From: Christian Kandeler
- struct compatibility
- Prev by Date: Re: NULL with representation other then all bits 0
- Next by Date: Re: NULL returned by fopen - where is a list of what's causing the error?
- Previous by thread: struct compatibility
- Next by thread: Re: struct compatibility
- Index(es):
Relevant Pages
|