This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: why is this result ?


On Jan 19, 2013 3:00 AM, "horseriver" wrote:
>
> On Fri, Jan 18, 2013 at 03:27:25PM +0000, Jonathan Wakely wrote:
> > >> ? printf("size of A is %d \n",sizeof(A));
> > >> ? //printf("size of B is %d \n",sizeof(B));
> >
> > Careful, you are using %d which expects an int but sizeof gives a size_t
> Thanks!
> I have not understand what you mean ? size_t is a unsigned int ,I think ?it does not matter here

It's quite easy to understand.

Your printf should be passed an int

The sizeof operator does not give you an int. On my platform it gives
a 64-bit integer. Even on your platform it does not give you an int,
unsigned int is not int.

The code is not portable, so you should be careful about writing and
using such code. If you compile with warnings you will get a warning
about it. It's your code so you can choose to ignore it if you think
you know better than the compiler. But you should be careful.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]