Re: how to initialize a structure

From: Dan Pop (Dan.Pop_at_cern.ch)
Date: 10/29/03


Date: 29 Oct 2003 15:42:45 GMT

In <bnohft$13rf0i$1@ID-166953.news.uni-berlin.de> Ramprasad A Padmanabhan <ramprasad@netcore.co.in> writes:

>I have a simple structure defined like this
>
>struct userid {
> char uid[MAXUIDLENGTH];
> int insize;
> int outsize;
>};
>typedef struct userid user;

Don't typedef struct's, unless you have a *good* reason for doing it.
Saving a few keystrokes in declarations doesn't count as a good reason.

All you can achieve with gratuitous typedef's is render the code less
readable.

>Now I want to define a user array and initialize it
>
>I tried something like this but doesnt work
>
>user *list[] = {
> {"user1",10,20},
> {"user2",0,20},
> {"user3",11,2}
> };
>
>Is there a way I can initialize this array while its declaration.

You need to learn how to declare things in C. Your initialiser is OK,
your declaration isn't. You're declaring an array of pointers to user,
NOT an array of user.

Dan

-- 
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de


Relevant Pages

  • Re: Properties
    ... public string Name ... The fact of the matter is that by adding having to add a field declaration ... There is no reason that you have given why this cannot be done. ... property but where theres a property theres a field and hence theres no ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: identifiers and modules
    ... Do you have a reason why a language should allow it? ... (let ((foo (transform-value foo))) ...)) ... working on a large nested function can easily use the wrong variable ... Given that allowing an inner declaration to override an outer ...
    (comp.lang.scheme)
  • Re: identifiers and modules
    ... Do you have a reason why a language should allow it? ... (let ((foo (transform-value foo))) ...)) ... working on a large nested function can easily use the wrong variable ... Given that allowing an inner declaration to override an outer ...
    (comp.lang.scheme)
  • Re: Scope of implied-do index
    ... but it seems like at least part of the reason. ... Implied DO variables with scope of the implied DO are one of my least ... but I can avoid using statement functions). ... is no place "reasonable" to put a declaration of them, ...
    (comp.lang.fortran)
  • RE: ActiveCell.Value copies unwanted currency format of source cel
    ... I just noticed something in my declaration of the variables but I'm not sure ... "JMB" wrote: ... decimals may be displayed). ... I cannot see any logical reason ...
    (microsoft.public.excel.programming)