Click here to Skip to main content
15,881,248 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 6:11
professionalDaniel Pfeffer2-Mar-21 6:11 
GeneralRe: Thought of the Day Pin
W Balboos, GHB2-Mar-21 6:14
W Balboos, GHB2-Mar-21 6:14 
GeneralRe: Thought of the Day Pin
Daniel Pfeffer2-Mar-21 6:13
professionalDaniel Pfeffer2-Mar-21 6:13 
GeneralRe: Thought of the Day Pin
W Balboos, GHB2-Mar-21 6:41
W Balboos, GHB2-Mar-21 6:41 
GeneralRe: Thought of the Day Pin
DerekT-P2-Mar-21 6:58
professionalDerekT-P2-Mar-21 6:58 
QuestionNew code in C? Where and why, versus C++? Pin
honey the codewitch2-Mar-21 3:36
mvahoney the codewitch2-Mar-21 3:36 
AnswerRe: New code in C? Where and why, versus C++? Pin
steveb2-Mar-21 3:57
mvesteveb2-Mar-21 3:57 
GeneralRe: New code in C? Where and why, versus C++? Pin
honey the codewitch2-Mar-21 4:08
mvahoney the codewitch2-Mar-21 4: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 4:14
professionalRage2-Mar-21 4:14 
GeneralRe: New code in C? Where and why, versus C++? Pin
honey the codewitch2-Mar-21 4:19
mvahoney the codewitch2-Mar-21 4:19 
GeneralRe: New code in C? Where and why, versus C++? Pin
Dave B 682-Mar-21 23:41
Dave B 682-Mar-21 23:41 
GeneralRe: New code in C? Where and why, versus C++? Pin
TheGreatAndPowerfulOz3-Mar-21 11:54
TheGreatAndPowerfulOz3-Mar-21 11:54 
GeneralRe: New code in C? Where and why, versus C++? Pin
Rick York2-Mar-21 5:55
mveRick York2-Mar-21 5:55 
GeneralRe: New code in C? Where and why, versus C++? Pin
steveb2-Mar-21 15:16
mvesteveb2-Mar-21 15:16 
GeneralRe: New code in C? Where and why, versus C++? Pin
Rick York2-Mar-21 16:10
mveRick York2-Mar-21 16:10 
GeneralRe: New code in C? Where and why, versus C++? Pin
Matt McGuire3-Mar-21 5:09
professionalMatt McGuire3-Mar-21 5:09 
AnswerRe: New code in C? Where and why, versus C++? Pin
Greg Utas2-Mar-21 4:01
professionalGreg Utas2-Mar-21 4:01 
GeneralRe: New code in C? Where and why, versus C++? Pin
honey the codewitch2-Mar-21 4:17
mvahoney the codewitch2-Mar-21 4:17 
GeneralRe: New code in C? Where and why, versus C++? Pin
Greg Utas2-Mar-21 4:23
professionalGreg Utas2-Mar-21 4:23 
GeneralRe: New code in C? Where and why, versus C++? Pin
honey the codewitch2-Mar-21 4:29
mvahoney the codewitch2-Mar-21 4:29 
GeneralRe: New code in C? Where and why, versus C++? Pin
Greg Utas2-Mar-21 4:32
professionalGreg Utas2-Mar-21 4:32 
GeneralRe: New code in C? Where and why, versus C++? Pin
honey the codewitch2-Mar-21 4:34
mvahoney the codewitch2-Mar-21 4:34 
GeneralRe: New code in C? Where and why, versus C++? Pin
pkfox2-Mar-21 11:10
professionalpkfox2-Mar-21 11:10 
AnswerRe: New code in C? Where and why, versus C++? Pin
Rage2-Mar-21 4:12
professionalRage2-Mar-21 4:12 
GeneralRe: New code in C? Where and why, versus C++? Pin
honey the codewitch2-Mar-21 4:15
mvahoney the codewitch2-Mar-21 4: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.