Jimmy Petersen <jip@dtv.dk> scribbled the following:[color=blue]
> Hello all,[/color]
[color=blue]
> After reading through chapter 6 of the faq I must admit
> I'm a bit confused :-).[/color]
[color=blue]
> What I am trying to do can be explained with the following
> three sample files:[/color]
[color=blue]
> var.c:
> float a[2][2] = {{1.0f, 2.0f},{3.0f, 4.0f}};[/color]
[color=blue]
> var.h:
> #ifndef var_h
> #define var_h[/color]
[color=blue]
> extern float a**;[/color]
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];
[color=blue]
> #endif[/color]
[color=blue]
> test.c
> #include "var.h"
> #include <stdio.h>[/color]
[color=blue]
> int main() {
> printf("a[0][0] = %f\n", a[0][0]);
> return(0);
> }[/color]
[color=blue]
> 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.[/color]
[color=blue]
> How do I do the two-dimensional thing?[/color]
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 (palaste@cc.helsinki.fi) ------------- 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