misalign flag in gcc 3.3
Yan.Periard@sungard.com
Yan.Periard@sungard.com
Wed Jun 4 15:07:00 GMT 2003
Hi,
I know this question seems to resurface every once in a while, but I was unable to find a definitive answer on the possible inclusion of a misalign compilation flag for gcc on sunOS. We are looking to switch from cc to gcc to save on the licencing cost but we are working with a legacy code base that extensively uses the misalign flag of cc. Sadly the code is core dumping using gcc. Here is a sample code that could help understand the problem. Is there any solution ? Where should I look for more details ?
If I am not posting to the right list please tell me so I can post this to the correct one.
thanks.
Yan Periard
/****** Example code *******/
#include <stdio.h>
#include <malloc.h>
int
main(void)
{
char *chunk;
int data;
int *data_p;
chunk = (char *) malloc(sizeof(int) * 2);
printf("chunk = %08x\n", chunk);
/*
* This should be valid, data is aligned properly.
*/
data_p = &data;
*data_p = 1;
printf("*data_p = %d, data_p = %08x\n", *data_p, data_p);
/*
* This should also be valid, chunk is probably aligned properly.
*/
data_p = (int *) chunk;
*data_p = 2;
printf("*data_p = %d, data_p = %08x\n", *data_p, data_p);
/*
* This should cause an alignment bus fault. chunk + 1 is byte
* aligned, but is not aligned to an int.
*/
*chunk = 'C';
data_p = (int *) (chunk + 1);
/* Prints ok, using cc or gcc on SunOS 5.8 */
printf("*chunk = %c\n", *chunk );
*data_p = 3;
/* Cores with a bus error using cc and gcc */
/* Works using cc -misalign */
/* Is there a way to make this work using gcc on SunOs */
printf("*data_p = %d, data_p = %08x\n", *data_p, data_p);
return 0;
}
More information about the Gcc-help
mailing list