Click here to Skip to main content
15,174,364 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Thought of the Day Pin
Daniel Pfeffer2-Mar-21 7:11
professionalDaniel Pfeffer2-Mar-21 7:11 
GeneralRe: Thought of the Day Pin
W Balboos, GHB2-Mar-21 7:14
mveW Balboos, GHB2-Mar-21 7:14 
GeneralRe: Thought of the Day Pin
Daniel Pfeffer2-Mar-21 7:13
professionalDaniel Pfeffer2-Mar-21 7:13 
GeneralRe: Thought of the Day Pin
W Balboos, GHB2-Mar-21 7:41
mveW Balboos, GHB2-Mar-21 7:41 
GeneralRe: Thought of the Day Pin
DerekT-P2-Mar-21 7:58
professionalDerekT-P2-Mar-21 7:58 
QuestionNew code in C? Where and why, versus C++? Pin
honey the codewitch2-Mar-21 4:36
mvahoney the codewitch2-Mar-21 4:36 
AnswerRe: New code in C? Where and why, versus C++? Pin
steveb2-Mar-21 4:57
Membersteveb2-Mar-21 4:57 
GeneralRe: New code in C? Where and why, versus C++? Pin
honey the codewitch2-Mar-21 5:08
mvahoney the codewitch2-Mar-21 5:08 
Maybe I just vastly misunderstand C++, but AFAIK you don't have to use ctors, which are basically "operator overloads" in a sense for object "creation/instantiation/initatialization". If they don't do anything the compiler doesn't generate code for them.

And addressof & does the same thing in C as it does in C++, unless you overload it.

The theme here is, if you don't use the feature, it doesn't produce the code to run the feature.

So if anything it seems a matter of education? Knowing what C++ will generate and what it won't.

I write code for real time devices in C++ all the time. There's no more latency than C.

Consider the following:

C++
class A {
public:
  int x;
};

This generates the same exact code as
C++
struct A {
  int x;
};


There are no constructors there. x will not get initialized on instantiation because I didn't write code for it. They are also both sizeof(int) in size.

If i needed initialization
C++
class A {
public:
  int x;
  A() : x(0) {}
  // i'm omitting the big-5 here
};

this is no different than if i needed initialization in C except it's cleaner:

C++
struct A {
  int x;
};
void initializeA(struct A *a) {
  // can't remember if -> is strictly C++ or not
  (*a).x=0;
}


The former doesn't pollute the namespace, and also prevents the case of forgetting to call the initialization function.
Real programmers use butterflies


modified 2-Mar-21 10:23am.

GeneralRe: New code in C? Where and why, versus C++? Pin
Rage2-Mar-21 5:14
professionalRage2-Mar-21 5:14 
GeneralRe: New code in C? Where and why, versus C++? Pin
honey the codewitch2-Mar-21 5:19
mvahoney the codewitch2-Mar-21 5:19 
GeneralRe: New code in C? Where and why, versus C++? Pin
Dave B 683-Mar-21 0:41
MemberDave B 683-Mar-21 0:41 
GeneralRe: New code in C? Where and why, versus C++? Pin
TheGreatAndPowerfulOz3-Mar-21 12:54
MemberTheGreatAndPowerfulOz3-Mar-21 12:54 
GeneralRe: New code in C? Where and why, versus C++? Pin
Rick York2-Mar-21 6:55
mveRick York2-Mar-21 6:55 
GeneralRe: New code in C? Where and why, versus C++? Pin
steveb2-Mar-21 16:16
Membersteveb2-Mar-21 16:16 
GeneralRe: New code in C? Where and why, versus C++? Pin
Rick York2-Mar-21 17:10
mveRick York2-Mar-21 17:10 
GeneralRe: New code in C? Where and why, versus C++? Pin
Matt McGuire3-Mar-21 6:09
professionalMatt McGuire3-Mar-21 6:09 
AnswerRe: New code in C? Where and why, versus C++? Pin
Greg Utas2-Mar-21 5:01
mveGreg Utas2-Mar-21 5:01 
GeneralRe: New code in C? Where and why, versus C++? Pin
honey the codewitch2-Mar-21 5:17
mvahoney the codewitch2-Mar-21 5:17 
GeneralRe: New code in C? Where and why, versus C++? Pin
Greg Utas2-Mar-21 5:23
mveGreg Utas2-Mar-21 5:23 
GeneralRe: New code in C? Where and why, versus C++? Pin
honey the codewitch2-Mar-21 5:29
mvahoney the codewitch2-Mar-21 5:29 
GeneralRe: New code in C? Where and why, versus C++? Pin
Greg Utas2-Mar-21 5:32
mveGreg Utas2-Mar-21 5:32 
GeneralRe: New code in C? Where and why, versus C++? Pin
honey the codewitch2-Mar-21 5:34
mvahoney the codewitch2-Mar-21 5:34 
GeneralRe: New code in C? Where and why, versus C++? Pin
pkfox2-Mar-21 12:10
professionalpkfox2-Mar-21 12:10 
AnswerRe: New code in C? Where and why, versus C++? Pin
Rage2-Mar-21 5:12
professionalRage2-Mar-21 5:12 
GeneralRe: New code in C? Where and why, versus C++? Pin
honey the codewitch2-Mar-21 5:15
mvahoney the codewitch2-Mar-21 5:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.