C
Christian Wittrock
Hi,
What does ANSI C say about casting an 8 bit pointer to a 16 bit one,
when the byte pointer is pointing to an odd address? I have detected a
problem in the Samsung CalmShine 16 compiler. This compiler I use for
the Samsung 16 bit Smartcard chips and I want to know if it is
compliant with the ANSI standard or if it violates it.
Have a look at this super simple example, where the value of b is
incorrect:
#include <stdio.h>
// Define an array in the EEPROM memory at address 0x081000
char data[8]={0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07} _at_
0x81000, eeprom;
int main ( void )
{
char a;
short b;
long c;
char* bpData;
// Set up the pointer to point to an odd address
bpData = &data[1];
// read a byte from an even address
a= *(bpData + 1);
// Read a word from an odd address. This causes problems. Instead of
// getting 0x0102 I get 0x001. What does ANSI C say about this?
b= *(short*)(bpData) ;
// just to check the value of the pointer, if the value of it is to
be stored in a variable
c= (long)bpData;
return 0x0 ;
}
What does ANSI C say about casting an 8 bit pointer to a 16 bit one,
when the byte pointer is pointing to an odd address? I have detected a
problem in the Samsung CalmShine 16 compiler. This compiler I use for
the Samsung 16 bit Smartcard chips and I want to know if it is
compliant with the ANSI standard or if it violates it.
Have a look at this super simple example, where the value of b is
incorrect:
#include <stdio.h>
// Define an array in the EEPROM memory at address 0x081000
char data[8]={0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07} _at_
0x81000, eeprom;
int main ( void )
{
char a;
short b;
long c;
char* bpData;
// Set up the pointer to point to an odd address
bpData = &data[1];
// read a byte from an even address
a= *(bpData + 1);
// Read a word from an odd address. This causes problems. Instead of
// getting 0x0102 I get 0x001. What does ANSI C say about this?
b= *(short*)(bpData) ;
// just to check the value of the pointer, if the value of it is to
be stored in a variable
c= (long)bpData;
return 0x0 ;
}