Re: Multidimensional array problems

From: Al Bowers (xabowers_at_rapidsys.com)
Date: 04/05/04


Date: Mon, 05 Apr 2004 15:48:59 -0400


Jimmy Petersen wrote:
> 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**;
>
> #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?
>

Change, in var.h
extern float **a;
to
extern float a[2][2];

-- 
Al Bowers
Tampa, Fl USA
mailto: xabowers@myrapidsys.com (remove the x to send email)
http://www.geocities.com/abowers822/


Relevant Pages

  • Re: offsetof
    ... Not just your reading the FAQ, ... this is why offsetof macro is implementation specific. ... > If you looks in the system headers for your implementation you ... If two pointers to objects of the same type are subtracted ...
    (comp.lang.c)
  • Re: Holding different classes.
    ... a single type. ... pointers to objects that belong to a single class hierarchy. ... a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq ...
    (alt.comp.lang.learn.c-cpp)
  • Re: pointers and files
    ... I'm wrk prj C. ... > address as that of the first char. ... pointers to FILE ... C++ Faq: http://www.parashift.com/c++-faq-lite ...
    (comp.lang.c)
  • Re: [OT] K&R Wishlist
    ... case of pointers, you can easily end up using the address of an array ... (And read the rest of the FAQ while you're ... understanding of the language. ... system-specific newsgroup. ...
    (comp.lang.c)
  • Re: A few things remain unclear...
    ... > understand(Feel free to direct me to a tutorial or a FAQ ... In a struct each field has its own storage area. ... to literal should be pointers to constant data. ... should be "char *". ...
    (comp.lang.c)