delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/22/12:00:33

From: Simon <s DOT j DOT harris AT ic DOT ac DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Data types
Date: Thu, 22 Jan 1998 16:13:31 +0000
Organization: Imperial College
Lines: 41
Message-ID: <34C7702B.5A5A@ic.ac.uk>
References: <34C53551 DOT D297940B AT jet DOT es> <199801210107 DOT UAA22018 AT p2 DOT acadia DOT net> <34C55D58 DOT DCE814CD AT cornell DOT edu>
Reply-To: s DOT j DOT harris AT ic DOT ac DOT uk
NNTP-Posting-Host: linpc.me.ic.ac.uk
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

A. Sinan Unur wrote:
> 
> Scott Warner wrote:
> >
> > something like
> >
> > #include<stdio.h>
> >
> > int main(void)
> > {
> >   int i;
> >   char c;
> >   float f;
> >
> >   printf("Size of integer: %d\n", sizeof(i);
> >   printf("Size of char: %d\n", sizeof(c);
> >   printf("Size of float: %d\n", sizeof(f);
> >
> >   return 0;
> > }
> >
> 
> you don't need to declare any variables. sizeof(type) is a constant
> expression of size_t. incidentally, did you try to compile the above
> with -Wall?
> 
>   printf("Size of integer: %lu\n", sizeof(int);
>   printf("Size of char:    %lu\n", sizeof(char);
>   printf("Size of float:   %lu\n", sizeof(float);
> 
> etc. is fine.
> 
For a truly conforming program each sizeof(...) should be
preceeded by (unsigned long) to ensure that it is cast
correctly to the type expected in the printf format string.
There is no guarantee that a result of type size_t is an
unsigned long (even though it happens to be in the current 
version of DJGPP). I believe the trailing parenthesis has
been dealt with elsewhere.

Simon.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019