Dear All
I am using gpc 2.1 version on sun solaris 2.8 .
I have problem with the accesing structures containing real variables.
I observed following things
1) I checked size of structures containing real varibles using sizeof function,I found out that memory allocated is always in multiples of 8,If I use -fpack-struct option it is allocating correctly but I am unable to access the address of my struct variable as it is packed?
2) I am always getting 'signal SIGSEGV, Segmentation fault' error while accessing real variables of my structures.I am suspecting some problem with memory allocation of structures containing real variables.One Interesting thing is, it is not happening with all structures containg real variables but only few.There is no problem with stack overflow.
Please suggest me some way to get rid of this error
Regards Hari
__________________________________ Start your day with Yahoo! - Make it your home page! http://www.yahoo.com/r/hs
vanam srihari kumar wrote:
I am using gpc 2.1 version on sun solaris 2.8 .
I have problem with the accesing structures containing real variables.
I observed following things
- I checked size of structures containing real
varibles using sizeof function,I found out that memory allocated is always in multiples of 8,If I use -fpack-struct option it is allocating correctly but I am unable to access the address of my struct variable as it is packed?
Try --maximum-field-algnment=8 instead of --pack-struct. Note that this may slowdown your program (just as --pack-struct does), so you can use instead
{$local maximum-field-alignment=8} type mystruc = ...; {$endlocal}
only when needed.
- I am always getting 'signal SIGSEGV, Segmentation
fault' error while accessing real variables of my structures.I am suspecting some problem with memory allocation of structures containing real variables.One Interesting thing is, it is not happening with all structures containg real variables but only few.There is no problem with stack overflow.
A configuration problem in the compiler back-end ? Something else ? What is in your opinion the "correct" size of a real and why must it be that size ? Does the segmentation fault occur when interfacing with other software, e.g. linked-in libraries or system routines ? Can you reproduce the problem with a testprogram ? What about running the gpc testsuite ?
Regards,
Adriaan van Os
vanam srihari kumar wrote:
I am using gpc 2.1 version on sun solaris 2.8 .
I have problem with the accesing structures containing real variables.
I observed following things
- I checked size of structures containing real
varibles using sizeof function,I found out that memory allocated is always in multiples of 8,If I use -fpack-struct option it is allocating correctly but I am unable to access the address of my struct variable as it is packed?
Try --maximum-field-algnment=8 instead of --pack-struct. Note that this may slowdown your program (just as --pack-struct does), so you can use instead
{$local maximum-field-alignment=8} type mystruc = ...; {$endlocal}
only when needed.
- I am always getting 'signal SIGSEGV, Segmentation
fault' error while accessing real variables of my structures.I am suspecting some problem with memory allocation of structures containing real variables.One Interesting thing is, it is not happening with all structures containg real variables but only few.There is no problem with stack overflow.
A configuration problem in the compiler back-end ? Something else ? What is in your opinion the "correct" size of a real and why must it be that size ? Does the segmentation fault occur when interfacing with other software, e.g. linked-in libraries or system routines ? Can you reproduce the problem with a testprogram ? What about running the gpc testsuite ?
"Porting UNIX Applications to the Solaris Operating Environment" http://developers.sun.com/solaris/articles/portingUNIXapps.html mentions the use of the -misalign and -misalign2 options, but I don't know if it is related.
Regards,
Adriaan van Os
vanam srihari kumar wrote:
Dear All
I am using gpc 2.1 version on sun solaris 2.8 .
I have problem with the accesing structures containing real variables.
I observed following things
- I checked size of structures containing real
varibles using sizeof function,I found out that memory allocated is always in multiples of 8,If I use -fpack-struct option it is allocating correctly but I am unable to access the address of my struct variable as it is packed?
GPC real is the same as C double, so on Sparc it takes 8 bytes and requires 8 byte alignment. So size beeing multiple of 8 is "correct" and anything else is "incorrect". If you really need different layout, you can force it, but you may run into troubles
Sparc is a strict alignment machine
- I am always getting 'signal SIGSEGV, Segmentation
fault' error while accessing real variables of my structures.I am suspecting some problem with memory allocation of structures containing real variables.One Interesting thing is, it is not happening with all structures containg real variables but only few.There is no problem with stack overflow.
Do you mean access from Pascal or access from C? If from C then note that Sparc is a strict alignment machine and will crash if you access misaligned data, so the problem may be due to packing (however, IIRC you would get BUS ERROR). If the problem is due to packing/alignment the simplest solution is to let GPC to properly align your data. If you need different alignment in records you must first copy record fields to aligned variables and access the copy.