Re: Variable array sizes as members ?
- From: Barry Schwarz <schwarzb@xxxxxxxx>
- Date: Sun, 19 Jul 2009 10:47:23 -0700
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
.
- References:
- Variable array sizes as members ?
- From: Robby
- RE: Variable array sizes as members ?
- From: Robby
- Variable array sizes as members ?
- Prev by Date: Re: Variable array sizes as members ?
- Next by Date: Re: Variable array sizes as members ?
- Previous by thread: Re: Variable array sizes as members ?
- Next by thread: Re: Variable array sizes as members ?
- Index(es):
Relevant Pages
|