At 12:39 AM 12/26/2004 -0000, dragtriumph writeth:
>OK, I'm new here and new to C.  I'm using the DJGPP (GNU) setup to
>learn C.  I'm having some difficulty accessing a structure ,which I
>believe I defined globally, inside a function.

Wow.  I didn't think anyone used DJGPP still.  It is an "okay"
middle-ground between DOS and Windows without actually being able to make
Windows calls, but gets you a flat 32-bit protected mode memory model.

>      cyl_vol = &(*ptr_engine.bore);

This line is your problem.  You probably need to learn about how pointers
work a bit more before throwing random address-of and dereferences all over
the place.

Assuming ptr_engine is a valid pointer to a structure, which of the
following dereferencing methods is different?
A)  ptr_engine->bore
B)  ptr_engine[0].bore
C)  (*ptr_engine).bore
D)  They are all the same.

If you answered D, you are right.  They may not generate the same assembler
code under an optimizing compiler, but the compiler will ultimately make
sure that all three do the same identical thing.

You will also note that there is no address-of in there.  You don't want
the address-of a float to store into a float.  The compiler will, at the
very least, complain about the mismatched types (i.e. float != float *).

So, try this instead:

cyl_vol = ptr_engine->bore;


Thomas J. Hruska
[EMAIL PROTECTED]

Shining Light Productions
Home of the Nuclear Vision scripting language and ProtoNova web server.
http://www.slproweb.com/



To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>.


Yahoo! Groups Sponsor
ADVERTISEMENT
click here


Yahoo! Groups Links

Reply via email to