Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3311578
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:53:36+00:00 2026-05-17T21:53:36+00:00

After a few years coding in C++, I was recently offered a job coding

  • 0

After a few years coding in C++, I was recently offered a job coding in C, in the embedded field.

Putting aside the question of whether it’s right or wrong to dismiss C++ in the embedded field, there are some features/idioms in C++ I would miss a lot. Just to name a few:

  • Generic, type-safe data structures (using templates).
  • RAII. Especially in functions with multiple return points, e.g. not having to remember to release the mutex on each return point.
  • Destructors in general. I.e. you write a d’tor once for MyClass, then if a MyClass instance is a member of MyOtherClass, MyOtherClass doesn’t have to explicitly deinitialize the MyClass instance – its d’tor is called automatically.
  • Namespaces.

What are your experiences moving from C++ to C?
What C substitutes did you find for your favorite C++ features/idioms? Did you discover any C features you wish C++ had?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:53:36+00:00Added an answer on May 17, 2026 at 9:53 pm

    Working on an embedded project, I tried working in all C once, and just couldn’t stand it. It was just so verbose that it made it hard to read anything. Also, I liked the optimized-for-embedded containers I had written, which had to turn into much less safe and harder to fix #define blocks.

    Code that in C++ looked like:

    if(uart[0]->Send(pktQueue.Top(), sizeof(Packet)))
        pktQueue.Dequeue(1);
    

    turns into:

    if(UART_uchar_SendBlock(uart[0], Queue_Packet_Top(pktQueue), sizeof(Packet)))
        Queue_Packet_Dequeue(pktQueue, 1);
    

    which many people will probably say is fine but gets ridiculous if you have to do more than a couple “method” calls in a line. Two lines of C++ would turn into five of C (due to 80-char line length limits). Both would generate the same code, so it’s not like the target processor cared!

    One time (back in 1995), I tried writing a lot of C for a multiprocessor data-processing program. The kind where each processor has its own memory and program. The vendor-supplied compiler was a C compiler (some kind of HighC derivative), their libraries were closed source so I couldn’t use GCC to build, and their APIs were designed with the mindset that your programs would primarily be the initialize/process/terminate variety, so inter-processor communication was rudimentary at best.

    I got about a month in before I gave up, found a copy of cfront, and hacked it into the makefiles so I could use C++. Cfront didn’t even support templates, but the C++ code was much, much clearer.

    Generic, type-safe data structures (using templates).

    The closest thing C has to templates is to declare a header file with a lot of code that looks like:

    TYPE * Queue_##TYPE##_Top(Queue_##TYPE##* const this)
    { /* ... */ }
    

    then pull it in with something like:

    #define TYPE Packet
    #include "Queue.h"
    #undef TYPE
    

    Note that this won’t work for compound types (e.g. no queues of unsigned char) unless you make a typedef first.

    Oh, and remember, if this code isn’t actually used anywhere, then you don’t even know if it’s syntactically correct.

    EDIT: One more thing: you’ll need to manually manage instantiation of code. If your “template” code isn’t all inline functions, then you’ll have to put in some control to make sure that things get instantiated only once so your linker doesn’t spit out a pile of “multiple instances of Foo” errors.

    To do this, you’ll have to put the non-inlined stuff in an “implementation” section in your header file:

    #ifdef implementation_##TYPE
    
    /* Non-inlines, "static members", global definitions, etc. go here. */
    
    #endif
    

    And then, in one place in all your code per template variant, you have to:

    #define TYPE Packet
    #define implementation_Packet
    #include "Queue.h"
    #undef TYPE
    

    Also, this implementation section needs to be outside the standard #ifndef/#define/#endif litany, because you may include the template header file in another header file, but need to instantiate afterward in a .c file.

    Yep, it gets ugly fast. Which is why most C programmers don’t even try.

    RAII.

    Especially in functions with multiple return points, e.g. not having to remember to release the mutex on each return point.

    Well, forget your pretty code and get used to all your return points (except the end of the function) being gotos:

    TYPE * Queue_##TYPE##_Top(Queue_##TYPE##* const this)
    {
        TYPE * result;
        Mutex_Lock(this->lock);
        if(this->head == this->tail)
        {
            result = 0;
            goto Queue_##TYPE##_Top_exit:;
        }
    
        /* Figure out `result` for real, then fall through to... */
    
    Queue_##TYPE##_Top_exit:
        Mutex_Lock(this->lock);
        return result;
    }
    

    Destructors in general.

    I.e. you write a d’tor once for MyClass, then if a MyClass instance is a member of MyOtherClass, MyOtherClass doesn’t have to explicitly deinitialize the MyClass instance – its d’tor is called automatically.

    Object construction has to be explicitly handled the same way.

    Namespaces.

    That’s actually a simple one to fix: just tack a prefix onto every symbol. This is the primary cause of the source bloat that I talked about earlier (since classes are implicit namespaces). The C folks have been living this, well, forever, and probably won’t see what the big deal is.

    YMMV

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Kinda of embarrassing to ask this question after few years working with Hibernate... I
I've recently started using oracle after a few years of using mysql. I was
I have recently started to use Eclipse after using IntelliJ for a few years.
I decided that I was ready to try something new, after a few years
After doing web development (php/js) for the last few years i thought it is
I am aware that there were similar questions in past few years, but after
I'm just getting back into coding after a few year hiatus and I'm trying
I'm new to Java after working for a few years in PHP and I'm
just starting with cakephp and almost with php after a few years without use
I'm just meddling with OSX after a few years on Linux. There's a lot

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.