Re: odd compiler behaviour?
On Fri, Mar 14, 2003 at 04:00:22PM +0000, Bruynooghe Floris wrote:
> I can't see why the second program fails to compile, as far as
> I would expect these programs are identical.
> Does anyone knows what goes wrong?
Declaring variables "anywhere" is a C++ism. (One which I consider a
bit yucky, but that's just me.) So, if we take your second
program and modify your procedure a little...
~$ cat << EOF > prog2.c
#include <stdio.h>
#include <stdlib.h> // need this to use malloc()
int main()
{
char* record;
int record_size = 10;
record = (char*) malloc (record_size);
int letter = 'a';
int i;
for (i=0; i < record_size; i++)
{
record[i] = (char) letter++;
printf ("record[%d] = %c\n", i, record[i]);
}
return 0;
}
EOF
~$ g++ prog2.c # note this is now g++
~$ a.out
record[0] = a
record[1] = b
<snip>
record[9] = j
... now it works.
Pigeon
Reply to: