delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/08/09:38:43

From: Mirek Prywata <nospam-mpry AT fuw DOT edu DOT pl>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: problem with memory allocation (I think)
Date: Thu, 08 Jan 1998 13:44:14 +0100
Organization: ift
Lines: 25
Message-ID: <34B4CA1E.654A9C5F@fuw.edu.pl>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 980108105452 DOT 8789O-100000 AT is>
Reply-To: mpry AT fuw DOT edu DOT pl
NNTP-Posting-Host: solth2.fuw.edu.pl
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Eli Zaretskii wrote:
> 
> Also, please note that it is usually a bad idea to put a long into a
> buffere which was malloc'ed for int's, like you do:
> 
>    long i;
>    unsigned int *buffer;
>    ...
>       buffer[i] = i;
> 
> This works in DJGPP, since int and long are both 32-bit, but on other
> architectures it will crash.

Isn't it true (at least in ANSI C), that the above code will be compiled
as:

 	buffer[i]= (unsigned int)i;
What you say means, that you should not write:
 
   double x=5;
   int *buffer;
........
	buffer[i]= x;

							Mirek

- Raw text -


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