C history question. Struct member functions.

AI Thread Summary
The discussion centers on the differences between "struct" in C and C++. While "struct" in C is similar to "record" in Pascal, it lacks member functions. In contrast, C++ allows "struct" to have member functions, making it functionally similar to "class," with the key distinction being that members of a struct are public by default. This functionality was introduced with C++ and has been part of the language since at least the first ISO standard in 1998. C does not support member functions, although C structs can contain pointers to functions, which offers some similar capabilities. The conversation reflects a desire to understand the historical development of these features in C++.
uart
Science Advisor
Messages
2,797
Reaction score
21
Old Pascal/Delphi programmer here with a question about c. I can kinda make my way around in c/c++ but I'm no expert.

I always thought the "struct" data type in c was just a mixed data type similar to "record" in Pascal. Now I find that "struct" in c++ can have member functions and basically do everything that "class" can do.

I was just wondering when this functionality entered or if it was always there? Was it something that was added in c++ (so not in c) or was it a feature added at some other time (or even was it there from the beginning of c)?

Thanks. :)
 
Technology news on Phys.org
Basically, there is no difference between structure and Class in C++. The only difference is that the default visibility of members in structure is public.

I think, once the concept of class was used in C++, they realized class was just an extension to structure, and they felt they should ... Ok, leave out, I am just fantasizing. :). I really don't know anything about the developmental stages of C++. Sorry.
 
I_am_learning said:
Basically, there is no difference between structure and Class in C++. The only difference is that the default visibility of members in structure is public.

I think, once the concept of class was used in C++, they realized class was just an extension to structure, and they felt they should ... Ok, leave out, I am just fantasizing. :). I really don't know anything about the developmental stages of C++. Sorry.

Yeah I've recently been refreshing my knowledge of c++ and that's when I notice this. "Stuct" seems to be pretty much the same as "class" except for differences in the defaults for public/private. I understand that, I'm just wondering when this functionality entered the language. Was it something added to c++ or did it come earlier/later than that?
 
C has no notion of member functions. Member functions in structs are purely a C++ thing, and have been part of C++ since at least the first ISO standard around 1998, probably earlier.

(as far as I know)

I didn't keep my old version of Bjarne Stroustrup's The C++ Programming Language from the early 1990s, which would probably say what the situation was at that time.
 
As mentioned, C doesn't support member functions, but C structs can have pointers to functions, which is similar.
 
Last edited:
Thanks for the info jtball and rcgldr. :)
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top