Re: Variable array sizes as members ?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Sat, 18 Jul 2009 19:03:01 -0700, Robby
<Robby@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

snip

#define NUL 0

Is there some reason you cannot use the standard macro NULL? Since
you only use it for pointers, you would be better served declaring it
#define NUL (void*)0
so that if you ever need to use it as an argument to a variadic
function there can be no mistaking it for an int.


typedef struct tag_xxx
{
long h[10];
}abc;

typedef struct tag_lb_table
{
long lb_items[5];
struct tag_xxx *xx;

Why do you go to the trouble of defining a typedef if you don't want
to use it?

}lb_table;


int main()
{
abc zzz[1]={1,2,3,4,5,6,7,8,9,0};

lb_table lb_dct1arr[] = {
{ 0, 0, 0, 0, 0}, zzz, //<< Compiler gives error here too!
{ 181, 182, 183, 184, 0}, NUL
{ 185, 184, 183, 0, 0} NUL,
};

// So I can access data in ZZ array, I am trying like this:
//lb_dct1arr[0].zzz[0] ... and I am lost! Someone please help!

There is no object or type ZZ in this code. There is no member zzz in
the struct lb_table. Assuming that you do assign the address of zzz
to member xx in the first element of your array of struct, you would
reference one of the ten long elements with
lb_dctarr[0].xx->h[i]
or the equivalent
lb_dct1arr[0].xx[0].h[i]


return 0;
}
========================================

I am getting the following error:

1>c:\_dts_programming\c_programming\c\c_tests\c_string_samples\misc_c_samples\varraysasmembers.c(26)
: warning C4047: 'initializing' : 'long' differs in levels of indirection
from 'abc *'

Since you didn't show us the real code, we are equally lost.


What is wrong with zzz... isn't it an abc type, which is a tag_xxx ... and
if we need a pointer of tag_xxx type, why can't we supply the name of the
array as the address ?

Could this be a compiler problem since in the past you have been using
one that is not even C90 compliant.

--
Remove del for email
.



Relevant Pages

  • Re: Array of pointers in a struct
    ... >typedef struct trieNode ... This is an array of 27 pointers. ... >And this is the code I make a new trie node, initialize and return it. ...
    (comp.lang.c)
  • Re: Problem in the C Structure code - pls help me.
    ... you define List as an array of 100 pointers to "struct ... All of these scribble on some unknown memory. ...
    (comp.lang.c)
  • Re: memory management
    ... I don't have a copy of the standard available to ... Accessing out of declared bounds of an array is ... floating-point and very occasionally pointers. ... This is called the 'struct hack', see 2.6 in the C FAQ at the usual ...
    (comp.lang.ada)
  • RE: Variable array sizes as members ?
    ... typedef struct tag_lb_table ... int main ... // So I can access data in zzz array, ... isn't it an abc type, ...
    (microsoft.public.vc.language)
  • Re: Data importing BUS ERROR
    ... You declare an array of 1000 pointers to struct. ... Then you malloc memory for 1 struct, ...
    (comp.lang.c)