Re: structures....

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



Robby wrote:
Hello QbProg and Drew,

I declared the

struct INPUT *z;

in the API.h file instead of the ACM152.h file. When this line of
code was declared in the ACM152.h file, the compiler did not see it
and so at compile time it generated the errors above. Now the program
compiles. Thankyou for your feedback !

Well it shouldn't be working. You're not using the name "INPUT"
consistently. In one place it's a struct tag, in another it's a typedef.
Be consistent (and I'm not sure you can forward typedef a struct the way you
can forward declare it, I would always include the header that defines the
struct and typedef first unless you have a really good reason not to).




=======================ACM152.h
struct INPUT *z;
int _a,_b,_c,_d,_e;
long _l;

...

INPUT z = API_config_MENU(); //ERROR HERE: EXPECTING A VARIABLE
You already declared z as INPUT *z in the h file.
So a simple
z = API_config_MENU(); would be sufficient.
also
INPUT * z = API_config_MENU();
would be ok, but you'd get a "redeclaration" error.


_a=z->DRAW_FAR_X; //ERROR HERE: ELEMENT IS NOT A MEMBER
_b=z->DRAW_FAR_Y; //ERROR HERE: ELEMENT IS NOT A MEMBER
_c=z->DRAW_LEAST_X; //ERROR HERE: ELEMENT IS NOT A MEMBER
_d=z->DRAW_LEAST_Y; //ERROR HERE: ELEMENT IS NOT A MEMBER
_l=z->MSG_NUM; //ERROR HERE: ELEMENT IS NOT A MEMBER
_e=z->SYMBOL_INTERVAL; //ERROR HERE: ELEMENT IS NOT A MEMBER

If you declare z as INPUT * this code is ok. If you declare z as
INPUT it is not , because you are using -> with a struct var (not a
pointer).

Also, remember to "free" z when you have done.

Bye
QbProg


.



Relevant Pages

  • Re: [PATCH 1/1] LinuxPPS: Pulse per Second support for Linux
    ... Follows my comments and then the patch, hope now I can came back into ... +typedef union pps_timeu { ... +typedef struct pps_info { ... different version of the compiler, and when different compiler options are ...
    (Linux-Kernel)
  • Re: Passing an array of structuresfrom a pointer?
    ... to only declare structs in headers and then define the ... the struct should be declared ... what if you have a simple array like this: ... In the header we would declare? ...
    (microsoft.public.vc.language)
  • Re: structs help
    ... >same name and the second compiler didn't like it. ... As I like to point out, the real problem with typedef is that it ... This is even more pronounced in the "typedef struct ..." ... time, though, I expect any programmer working on the zorgle program ...
    (comp.lang.c)
  • Re: Passing an array of structuresfrom a pointer?
    ... to only declare structs in headers and then define the ... the struct should be declared ... what if you have a simple array like this: ... It also returned the value of the pointer. ...
    (microsoft.public.vc.language)
  • Re: C90 penetration
    ... If we agree on a set of digits that includes all Latin 1 alpha, ... if 'double' were indeed a typedef for a struct ... And there are a number of other reasons why making "double" a typedef ... for a struct type would make a compiler non-conforming. ...
    (comp.lang.c)