28 ms·
In riposte: C++ willingly supports all previous security holes and adds a few more. why do we have structs and classes? all this stuff in the first week.
by throwawayaway 12y ago
In riposte: C++ willingly supports all previous security holes and adds a few more.
why do we have structs and classes? all this stuff in the first week.
- pjmlp 12y agoTo allow Bjarne to sell C++ to C developers, specially those ex-Assembly programmers that were force-feed to C. You don't need to learn C, just read "The Design and Evolution of C++".
- throwawayaway 12y agoBut how can you explain their existence and all the C++ behaviour derived from that without using C - you can't.
- pjmlp 12y agoYes, you can. I am having this discussion since 1993. Back when a I was teaching assistance in the late 90's, we never talked about C in our C++ classes, besides the initial history introduction. The fact that the C++ language contains a (almost) C compatible subset doesn't require students to be aware of it. It is all ANSI C++.
- throwawayaway 12y agook: why do structs exist and why are their members public? why don't you just use classes with public? i have been taught extremely poorly and am many years your junior. K&R/stan lipmann's "inside the C++ object model" was a huge "oh ok, I've been basically lied to the entire time"
- pjmlp 12y ago> why do structs exist and why are their members public? why don't you just use classes with public? To be able to reuse existing C code in a C++ compiler, while allowing them to participate in class hierarchies. This is the real reason, but you don't need to explain it like that to new C++ devs. Use struts when you just need a data container. Use classes when you need to add behaviour. Simple rule, no need to talk anything about C.
- throwawayaway 12y agopeople keep using this "new C++ devs" proviso, it's a red herring. to remind you: > What exactly do you need to know about C, that is not part of C++, to understand C++? why can't you memcpy classes but you can structs? it's a confederation of languages, i think coldtea's idea of representing it as a superset is excellent, you cannot understand C++ by taking out its C subset. if that's your attitude where it's not the real reason, but you think your explanation is sufficient: your withholding information is limiting my education and as a student i would hate that. your explanation isn't an explanation, it's an order/instruction without explanation, C++ is full of this. you only get to "why" with C.
- pjmlp 12y ago> why can't you memcpy classes but you can structs? Since when?! Try this on a struct and it will go boom! The only difference between structs and classes is the default access specifier. > C++ is full of this. you only get to "why" with C. No, you get the why by knowing Assembly and how computers work. Any system programming language since FORTRAN exposes the same set of issues. We never teached C at our university (during the 90's), first year students had Pascal followed by straight C++. If they ever need to use C, it was based on what they learned from C++. There were no C lectures, nor teaching what is C or C++. I never saw anyone speaking about learning BCPL to use K&R C, or having to learn Pascal to use Ada or Modula-2.
- throwawayaway 12y agostruct_type s1 = {0,0,0,0,0}; struct_type s2 = {0,1,2,3,4}; memcpy(s1, s2, sizeof(struct_type)); // wat is the problem :? > There were no C lectures, nor teaching what is C or C++. > Back when a I was teaching assistance in the late 90's, we never talked about C in our C++ classes What exactly do you mean by the first statement? You mean you never taught people the difference? You can't properly explain the existence of the struct data type without C, this is nothing to do with FORTRAN. > I never saw anyone speaking about learning BCPL to use K&R C, or having to learn Pascal to use Ada or Modula-2. that is not the argument I am making. the argument people are making is that you can learn C++ without learning C. they seem to be forgetting that in the process of understanding C++, you have to learn C. if you do not understand C, you cannot understand C++. to transplant your argument, if you take out all the keywords from BCPL that are shared with C and try to learn C without using them, you aren't going to get anywhere.