Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C history question. Struct member functions.

  1. Jul 29, 2011 #1


    User Avatar
    Science Advisor

    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. :)
  2. jcsd
  3. Jul 29, 2011 #2
    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.
  4. Jul 29, 2011 #3


    User Avatar
    Science Advisor

    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?
  5. Jul 29, 2011 #4


    User Avatar

    Staff: Mentor

    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.
  6. Jul 29, 2011 #5


    User Avatar
    Homework Helper

    As mentioned, C doesn't support member functions, but C structs can have pointers to functions, which is similar.
    Last edited: Jul 29, 2011
  7. Jul 29, 2011 #6


    User Avatar
    Science Advisor

    Thanks for the info jtball and rcgldr. :)
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook