[comp.sys.apple2] More about ORCA/C bug

neufeld@aurora.physics.utoronto.ca (Christopher Neufeld) (03/11/91)

   I finally tracked down the origin of the bug which has been causing
me so much trouble this weekend. The "sizeof" function returns the wrong
value for floating-point passed parameters of type other than extended.
This means that the "fwrite" command, which takes the size of the
argument as one of its parameters, writes too many bytes to the disk
file, which throws everything off when you try to read it back with the
correct "sizeof" values.
   Here is a program which demonstrates this effect.


#include <stdio.h>

void showsizes(a,b,c,d,e,f,g,h,i,j,k,l,m)
char a;
unsigned char b;
int c;
unsigned int d;
short e;
unsigned short f;
long g;
unsigned long h;
float i;
double j;
extended k;
comp l;
void *m;
{
  printf("sizeof(char a;) = %i\n",sizeof(a));
  printf("sizeof(unsigned char b;) = %i\n",sizeof(b));
  printf("sizeof(int c;) = %i\n",sizeof(c));
  printf("sizeof(unsigned int d;) = %i\n",sizeof(d));
  printf("sizeof(short e;) = %i\n",sizeof(e));
  printf("sizeof(unsigned short f;) = %i\n",sizeof(f));
  printf("sizeof(long g;) = %i\n",sizeof(g));
  printf("sizeof(unsigned long h;) = %i\n",sizeof(h));
  printf("sizeof(float i;) = %i\n",sizeof(i));
  printf("sizeof(double j;) = %i\n",sizeof(j));
  printf("sizeof(extended k;) = %i\n",sizeof(k));
  printf("sizeof(comp l;) = %i\n",sizeof(l));
  printf("sizeof(void *m;) = %i\n",sizeof(m));
  return;
}  


void main()
{
  char a = -24;
  unsigned char b = 24;
  int c = -900;
  unsigned int d = 900;
  short e = -900;
  unsigned short f = 900;
  long g = -70000L;
  unsigned long h = 70000L;
  float i = 1.0e30;
  double j = 1.0e300;
  extended k = 1.0e4800;
  comp l = 9e16;
  void *m;
  
  showsizes(a,b,c,d,e,f,g,h,i,j,k,l,m);
}

--- output follows ---

sizeof(char a;) = 1
sizeof(unsigned char b;) = 1
sizeof(int c;) = 2
sizeof(unsigned int d;) = 2
sizeof(short e;) = 2
sizeof(unsigned short f;) = 2
sizeof(long g;) = 4
sizeof(unsigned long h;) = 4
sizeof(float i;) = 10
sizeof(double j;) = 10
sizeof(extended k;) = 10
sizeof(comp l;) = 10
sizeof(void *m;) = 4



-- 
 Christopher Neufeld....Just a graduate student  | Note: new host.
 neufeld@aurora.physics.utoronto.ca    Ad astra! | helios will still
 cneufeld@{pnet91,pro-cco}.cts.com               | forward my mail to
 "Don't edit reality for the sake of simplicity" | me on aurora.