K
Kevin
I have two questions. I hope they are about C. I chose to post
here instead of comp.unix.programmer (or some other) because I do
think this is a C question.
Question 1:
%cat float.c
main() {
float **m = malloc(5 * sizeof(float*));
m[0] = malloc( sizeof(float) );
m[0][0] = 1.2;
printf("%f\n",m[0][0]);
}
Is this legal? I never really declare and assign so fast, but I
was wondering if it works because I'm lucky or if it really is
legal. Gcc doesn't like it much.
%gcc -c float.c
float.c: In function `main':
float.c:2: warning: initialization makes pointer from integer
without a cast float.c:3: warning: assignment makes pointer from
integer without a cast
Question 2:
(gdb) p sizeof(int)
$1 = 4
(gdb) p sizeof(long)
$2 = 4
I was expecting to see long a little bigger.
Why are they the same size?
Thank you.
here instead of comp.unix.programmer (or some other) because I do
think this is a C question.
Question 1:
%cat float.c
main() {
float **m = malloc(5 * sizeof(float*));
m[0] = malloc( sizeof(float) );
m[0][0] = 1.2;
printf("%f\n",m[0][0]);
}
Is this legal? I never really declare and assign so fast, but I
was wondering if it works because I'm lucky or if it really is
legal. Gcc doesn't like it much.
%gcc -c float.c
float.c: In function `main':
float.c:2: warning: initialization makes pointer from integer
without a cast float.c:3: warning: assignment makes pointer from
integer without a cast
Question 2:
(gdb) p sizeof(int)
$1 = 4
(gdb) p sizeof(long)
$2 = 4
I was expecting to see long a little bigger.
Why are they the same size?
Thank you.