View Full Version : c language
jaseweb
11-16-2000, 05:12 AM
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 ...
Don't Disturb
11-16-2000, 06:05 AM
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).]
convict@large
11-16-2000, 06:28 AM
"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:
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).]
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.
mike j
11-16-2000, 07:17 AM
www.informit.com (http://www.informit.com)
register and click the links to the free
library - you'll find a couple of 'online books' on C
Deiussum
11-16-2000, 08:02 AM
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.
Siwko
11-16-2000, 08:33 AM
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! http://www.opengl.org/discussion_boards/ubb/smile.gif
Siwko
Deiussum
11-16-2000, 12:37 PM
Originally posted by Siwko:
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! http://www.opengl.org/discussion_boards/ubb/smile.gif
Siwko
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? :P 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
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.