Click here to Skip to main content
15,885,985 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 5:34
jeron12-Mar-21 5:34 
GeneralRe: Thought of the Day Pin
W Balboos, GHB2-Mar-21 5:46
W Balboos, GHB2-Mar-21 5:46 
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 
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 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 
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 

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.