[Top][All Lists]

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

Re: [Tinycc-devel] wrong/incorrect result of sizeof

From: Christian Jullien
Subject: Re: [Tinycc-devel] wrong/incorrect result of sizeof
Date: Tue, 18 Jun 2013 09:53:17 +0200


I think there no "correct" result.
On a system that requires 64bit alignment for uint64_t, a C compiler is free
to add extra bytes padding for either processor required alignment or for
faster access.

With gcc you can force packed struct using __attribute__((__packed__))
But compiler may add extra code complexity when you access your data.

-----Original Message-----
From: address@hidden
[mailto:address@hidden On Behalf Of
Ariset Llerena
Sent: mardi 18 juin 2013 09:25
To: address@hidden
Subject: [Tinycc-devel] wrong/incorrect result of sizeof

the following code

#include <stdint.h>
#include <stdio.h>
struct foobar{
     uint16_t foo; // 4 bytes
     uint64_t bar; // 8 bytes
int main(){
     printf("%d\n", sizeof(struct foobar));
     return 0;

prints 16, gcc 4.7 prints 12 that is the correct result. Posted in

Tinycc-devel mailing list

reply via email to

[Prev in Thread] Current Thread [Next in Thread]