delorie.com/archives/browse.cgi | search |
X-Authentication-Warning: | delorie.com: mailnull set sender to djgpp-bounces using -f |
Message-ID: | <3C62A89A.9DF630C5@yahoo.com> |
From: | CBFalconer <cbfalconer AT yahoo DOT com> |
Organization: | Ched Research |
X-Mailer: | Mozilla 4.75 [en] (Win98; U) |
X-Accept-Language: | en |
MIME-Version: | 1.0 |
Newsgroups: | comp.os.msdos.djgpp |
Subject: | Re: Alignment problem |
References: | <3C629769 DOT AEAFB611 AT cyberoptics DOT com> |
Lines: | 74 |
Date: | Thu, 07 Feb 2002 16:18:18 GMT |
NNTP-Posting-Host: | 12.90.179.132 |
X-Complaints-To: | abuse AT worldnet DOT att DOT net |
X-Trace: | bgtnsc04-news.ops.worldnet.att.net 1013098698 12.90.179.132 (Thu, 07 Feb 2002 16:18:18 GMT) |
NNTP-Posting-Date: | Thu, 07 Feb 2002 16:18:18 GMT |
To: | djgpp AT delorie DOT com |
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
Reply-To: | djgpp AT delorie DOT com |
Eric Rudd wrote: > > When I execute the small program > > #include <stdio.h> > #include <stdlib.h> > > int main(void) { > void *ptr; > > ptr = malloc(1024); > if (((int) ptr) & 7) { > printf(" ptr %p not 8-byte aligned.\n", ptr); > } else { > printf(" ptr %p 8-byte aligned.\n", ptr); > } > free(ptr); > return 0; > } > > I get output like > > ptr 8f4e4 not 8-byte aligned. > > about half the time. I am currently running gcc 2.95.3, binutils > 2.11.2, CWSDPMI r5 under PC-DOS 6.3. The problem also exists in a DOS > box under Win95 (where CWSDPMI is not being used). > > I am calling gcc with the following options: > > -O2 > -march=pentium > -Wall > -fomit-frame-pointer > > I thought that this alignment problem had been solved in gcc 2.95 and > binutils 2.9.1. What should I do to diagnose this problem further? Is there a problem? The (int) cast is not necessarily valid. Try this modification (note alloc of 1023): #include <stdio.h> #include <stdlib.h> int main(void) { void *ptr; int v; int a, i; for (i = 0; i < 8; i++) { ptr = malloc(1023); v = (int)ptr; if (!(v & 31)) a = 32; else if (!(v & 15)) a = 16; else if (!(v & 7)) a = 8; else if (!(v & 3)) a = 4; else if (!(v & 1)) a = 2; else a = 1; printf(" ptr %p is %2d-byte aligned. (int)p = %d6\n", ptr, a, v); } return 0; } It looks as if the integer conversion is multiplying by 10 and adding 6. Which shouldn't matter because it is undefined anyhow. At any rate the displayed result is of the form 10n+6. -- Chuck F (cbfalconer AT yahoo DOT com) (cbfalconer AT XXXXworldnet DOT att DOT net) Available for consulting/temporary embedded and systems. (Remove "XXXX" from reply address. yahoo works unmodified) mailto:uce AT ftc DOT gov (for spambots to harvest)
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |