J
Joona I Palaste
Jimmy Petersen said:Hello all,
After reading through chapter 6 of the faq I must admit
I'm a bit confused.
What I am trying to do can be explained with the following
three sample files:
var.c:
float a[2][2] = {{1.0f, 2.0f},{3.0f, 4.0f}};
var.h:
#ifndef var_h
#define var_h
extern float a**;
a is declared as the wrong type here. Even though T[] and T* are
assignment-compatible types, T[][] and T** are not. Chris Torek can
explain this in detail. You should declare this as:
extern float (*a)[2];
or:
extern float a[2][2];
#endif
test.c
#include "var.h"
#include <stdio.h>
int main() {
printf("a[0][0] = %f\n", a[0][0]);
return(0);
}
This doesn't appear to be working though since the compiler (gcc)
reports "'a' undeclared". I know from the faq that arrays and
pointers are not the same but after having tried declaring 'a' as
'extern float* a[];' and 'extern float a[][];' I've found that
the only thing which compiles is 'extern float* a[];' but this
only gives me an array of pointers to unallocated memory.
How do I do the two-dimensional thing?
Try declaring a as "extern float (*a)[];". The way you compiled it, it
was an array of pointers - you need a pointer to an array.
--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Remember: There are only three kinds of people - those who can count and those
who can't."
- Vampyra