From: raines@jupiter.slac.stanford.edu (Paul E. Raines)
Subject: problems with flag -xtaso_short to cc
Date: 1996/02/29 [thread overview]
Message-ID: <yfs20ne99ts.fsf@jupiter.SLAC.Stanford.EDU> (raw)
To port some code from AIX, we wish to use 32-bit pointers. The
C compiler appears to provide the -xtaso_short flag for this.
We have found several problems with it. One is that it does not
seem to be consistant. Here is the output of a simple program to
print the size of objects. Note that witht he -xtaso_short flag,
sizeof(int*) is 4 while sizeof(&i) where i is an integer is still 8.
=================================================================
$ cc -g -taso -xtaso_short ptest.c -o ptest
$ ./ptest
Sizeof(int) = 4
Sizeof(int*) = 4
Sizeof(long) = 8
Sizeof(long*) = 4
Sizeof(i) = 4
Sizeof(&i) = 8
Sizeof(l) = 8
Sizeof(&l) = 8
$ cc -g ptest.c -o ptest
$ ./ptest
Sizeof(int) = 4
Sizeof(int*) = 8
Sizeof(long) = 8
Sizeof(long*) = 8
Sizeof(i) = 4
Sizeof(&i) = 8
Sizeof(l) = 8
Sizeof(&l) = 8
$ cat ptest.c
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
int main(int argc, char **argv)
{
int i;
long l;
printf("Sizeof(int) = %d\n", sizeof(int));
printf("Sizeof(int*) = %d\n", sizeof(int*));
printf("Sizeof(long) = %d\n", sizeof(long));
printf("Sizeof(long*) = %d\n", sizeof(long*));
printf("Sizeof(i) = %d\n", sizeof(i));
printf("Sizeof(&i) = %d\n", sizeof(&i));
printf("Sizeof(l) = %d\n", sizeof(l));
printf("Sizeof(&l) = %d\n", sizeof(&l));
exit(0);
}
=================================================================
The other problems is that the argv argument to main is still 64
bytes and if you pass argv to another function as (char **) and
try to access it with string functions, it core dumps. The simple
work around here was to copy the entire argv contents in main to
a local (char **) variable using repeated mallocs.
A similar problem to this is that many functions core-dump in
32-mode. One of these is tolower. The following code coredumps.
=================================================================
$ cat xtest.c
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
void cUtToUpper(const char* is,char* os){
int i, l=strlen(is);
for(i=0; i<l; i++) os[i]=toupper(is[i]);
os[i]=0;
}
main(int argc, char **argv)
{
char s1[100];
strcpy(s1,"event");
cUtToUpper(s1,s1);
printf("%s\n",s1);
}
$ cc -g xtest.c -o xtest
$ ./xtest
EVENT
$ cc -g -taso -xtaso_short xtest.c -o xtest
$ ./xtest
Segmentation fault (core dumped)
$ dbx xtest core
dbx version 3.11.8
Type 'help' for help.
Core file created by program "xtest"
signal Segmentation fault at [cUtToUpper:8 +0x4c,0x12001310] \
for(i=0; i<l; i++) os[i]=toupper(is[i]);
=================================================================
next reply other threads:[~1996-02-29 5:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-02-29 5:00 Paul E. Raines [this message]
1996-03-14 5:00 ` problems with flag -xtaso_short to cc Christian Koenigseder
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox