c language

can anybody explain

Structures and how to use it in ‘c’.

thanks

I’m not ure it’s a good forum to post this question …

A struct is just like a C++ class, but without member functions.

[This message has been edited by Don’t Disturb (edited 11-16-2000).]

“can anybody explain
Structures and how to use it in ‘c’.”
Sure.

To define a structure use the following:
typedef struct tagStructureName
{
VaribleType VaribleName;
}StructureName;

To create an instance of a structure do the following:
StructureName StructureInstanceName;

To access a member of a structure do this:
StructureInstanceName.VaribleName = value;

To access a member of a structure via a pointer do this:
PointerToStructureInstanceName->VaribleName = value;

Hows that? If you have any other questions then mail me at Daniel@TheRealityDysfunction.com but you should not be asking this sort of question in the Advanced topics forum ask instead in the beginners!

Cheers,

Daniel

Originally posted by Don’t Disturb:
[b]A struct is just like a C++ class, but without member functions.

[This message has been edited by Don’t Disturb (edited 11-16-2000).][/b]

Wrong. A struct is exactly like a class but with all the all members public instead of private. You can have member functions for structure too.

www.informit.com

register and click the links to the free
library - you’ll find a couple of ‘online books’ on C

Originally posted by Gorg:

Wrong. A struct is exactly like a class but with all the all members public instead of private. You can have member functions for structure too.

This is true for structs in C++, but not in pure C. Anyway, I agree that this type of question would probably be better asked on a different board.

Originally posted by Deiussum:
This is true for structs in C++, but not in pure C. Anyway, I agree that this type of question would probably be better asked on a different board.

Wrong again… you actually can have member functions in a pure C struct… though you must do it using pointers to functions. Sure, its a round about way of doing it, but where do you think C++ got its roots from? Not java!

Neener neener!

Siwko

Originally posted by Siwko:
[b] Wrong again… you actually can have member functions in a pure C struct… though you must do it using pointers to functions. Sure, its a round about way of doing it, but where do you think C++ got its roots from? Not java!

Neener neener!

Siwko[/b]

Heheh, ok. I was thinking of member functions in the traditional sense rather than using function pointers for that. You’re right, though. It’s a roundabout way of doing it but would work.

Pointers to functions is a bit below the belt, eh? :stuck_out_tongue: You sneak!

For the point of debate, pointers to functions are not member functions because they don’t have a pointer to THIS. So, I’d argue, althought structs can have fucntions, they’re not member functions, but more like friends.

<shrugs>

cheers,
John