Portability & the ARM Processor
by Trevor Harmon


Listing One

char c = -1;
if (c < 0)
  printf("c<0\n");
else
  printf("c>=0\n");

Listing Two 

char ch;
FILE* file;
file = fopen("textfile", "r");
while ((ch = getc(file)) != EOF)
  putchar(ch);

Listing Three 

struct SensorData
{
   unsigned char x_position;
   unsigned char y_position;
   unsigned char sensorID;
};
    ...
write(serial_port, sensor_data1,
  sizeof(struct SensorData));
write(serial_port, sensor_data2,
  sizeof(struct SensorData));


Listing Four

struct SensorData
{
   unsigned char x_position;
   unsigned char y_position;
   unsigned char sensorID;
} __attribute__ ((packed));


Listing Five 

char buf[5];
int* i = (int*)(buf+1);
// Simulate data read from network
buf[0]=1; buf[1]=2; buf[2]=3;
buf[3]=4; buf[4]=5;
printf("%08x\n", *i);


Listing Six

struct ethhdr 
{
  unsigned char h_dest[ETH_ALEN];
  unsigned char h_source[ETH_ALEN];
  unsigned short h_proto;
};







2


