Click here to Skip to main content
15,127,128 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
jeron12-Mar-21 6:34
Memberjeron12-Mar-21 6:34 
GeneralRe: Thought of the Day Pin
W Balboos, GHB2-Mar-21 6:46
mveW Balboos, GHB2-Mar-21 6:46 
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 
This is something I'm really curious about, and maybe it's just because I'm newish to coding small gadgets, though most of it is comfortable to me since I cut my teeth on 6502 CPUs back in the day.

What is the purpose of writing new code in C for targeting, well ... anything?

I've put away my C compiler and simply relied on limited use of C++ features to keep the footprint the same as it is in C:

1. no vtables. slightly complicates inheritance, as you can no longer do virtual ~foo() {}
2. extremely limited use of the STL, if at all. I typically use std::atomic if available, but not std::string, for example
3. judicious use of extern "C" when exporting my main, or importing "C" headers
4. no exceptions/SEH/etc, RTTI or other C++ frills that bloat code or stack

Why do I do it?

Primarily for that sweet sweet RAII, but also general source management. Classes can keep everything together. HPP based libraries are useful for simplifying distribution. public and private members replace the need for hiding in C files in many cases. and many other reasons.

Should I not be doing it? Is there a reason this is bad form?

Is there a reason you wouldn't?
Real programmers use butterflies

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 
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
mvaGreg 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
mvaGreg 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
mvaGreg 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 

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.