Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Sometimes C++ can be a PITA

Sometimes C++ can be a PITA

Scheduled Pinned Locked Moved The Lounge
announcementc++comquestion
14 Posts 8 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mike Hankey
    wrote on last edited by
    #1

    Working with an STM32 device and trying to implement program in c++. Every platform is a little different in the way it implements C++ so trying to learn the ins and outs on the STM32. Been working on a simple Timer singleton class for the past 6 hours and it's been 2 steps forward and 1 back. Should be fairly easy but there were so many gotchas that made it very frustrating.

    A home without books is a body without soul. Marcus Tullius Cicero PartsBin an Electronics Part Organizer - Release Version 1.4.0 (Many new features) JaxCoder.com Latest Article: EventAggregator

    J OriginalGriffO H C 4 Replies Last reply
    0
    • M Mike Hankey

      Working with an STM32 device and trying to implement program in c++. Every platform is a little different in the way it implements C++ so trying to learn the ins and outs on the STM32. Been working on a simple Timer singleton class for the past 6 hours and it's been 2 steps forward and 1 back. Should be fairly easy but there were so many gotchas that made it very frustrating.

      A home without books is a body without soul. Marcus Tullius Cicero PartsBin an Electronics Part Organizer - Release Version 1.4.0 (Many new features) JaxCoder.com Latest Article: EventAggregator

      J Offline
      J Offline
      jeron1
      wrote on last edited by
      #2

      Sounds painful, but also like article material.

      "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

      C 2 Replies Last reply
      0
      • M Mike Hankey

        Working with an STM32 device and trying to implement program in c++. Every platform is a little different in the way it implements C++ so trying to learn the ins and outs on the STM32. Been working on a simple Timer singleton class for the past 6 hours and it's been 2 steps forward and 1 back. Should be fairly easy but there were so many gotchas that made it very frustrating.

        A home without books is a body without soul. Marcus Tullius Cicero PartsBin an Electronics Part Organizer - Release Version 1.4.0 (Many new features) JaxCoder.com Latest Article: EventAggregator

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        I'm probably old fashioned, but I don't find C++ that helpful when it comes to embedded work - stick to C and assembler is my preferred route. The idea of embedded is to get the best performance out of limited resources (speed, memory and / or power) and the extra overhead of class based OOPs isn't necessarily a good idea. And it's way harder to keep an eye on memory management to ensure memory fragmentation doesn't rear its ugly head after 2 weeks of continual runtime ... :laugh:

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        M H C 3 Replies Last reply
        0
        • OriginalGriffO OriginalGriff

          I'm probably old fashioned, but I don't find C++ that helpful when it comes to embedded work - stick to C and assembler is my preferred route. The idea of embedded is to get the best performance out of limited resources (speed, memory and / or power) and the extra overhead of class based OOPs isn't necessarily a good idea. And it's way harder to keep an eye on memory management to ensure memory fragmentation doesn't rear its ugly head after 2 weeks of continual runtime ... :laugh:

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

          M Offline
          M Offline
          Mike Hankey
          wrote on last edited by
          #4

          OriginalGriff wrote:

          I don't find C++ that helpful when it comes to embedded work

          I disagree c++, I've used C++ on various platforms for years and never had a problem. I find; code size comparable, speed acceptable (you can also mix c++ and assembler). The Arduino platform uses c++ as it's major language and there are libraries for everything under the sun.

          A home without books is a body without soul. Marcus Tullius Cicero PartsBin an Electronics Part Organizer - Release Version 1.4.0 (Many new features) JaxCoder.com Latest Article: EventAggregator

          1 Reply Last reply
          0
          • M Mike Hankey

            Working with an STM32 device and trying to implement program in c++. Every platform is a little different in the way it implements C++ so trying to learn the ins and outs on the STM32. Been working on a simple Timer singleton class for the past 6 hours and it's been 2 steps forward and 1 back. Should be fairly easy but there were so many gotchas that made it very frustrating.

            A home without books is a body without soul. Marcus Tullius Cicero PartsBin an Electronics Part Organizer - Release Version 1.4.0 (Many new features) JaxCoder.com Latest Article: EventAggregator

            H Offline
            H Offline
            honey the codewitch
            wrote on last edited by
            #5

            I use the C runtimes with C++ language features on embedded. I avoid the STL and most of the C++ standard runtimes. Why? For the exact reasons you're running into - the C runtimes in general are far more consistent platform to platform. Furthermore, The STL is not set up to use the heap responsibly on constrained systems. You will get heap frag and eventual crashes without creating your own custom allocators for everything.

            Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

            M 1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              I'm probably old fashioned, but I don't find C++ that helpful when it comes to embedded work - stick to C and assembler is my preferred route. The idea of embedded is to get the best performance out of limited resources (speed, memory and / or power) and the extra overhead of class based OOPs isn't necessarily a good idea. And it's way harder to keep an eye on memory management to ensure memory fragmentation doesn't rear its ugly head after 2 weeks of continual runtime ... :laugh:

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

              H Offline
              H Offline
              honey the codewitch
              wrote on last edited by
              #6

              Forget classes. template and constexpr mean I can create faster/more efficient code in C++ than you can readily create in C. You don't have to use features that generate overhead in C++. Zero overhead C++ is a thing. Besides, Generic Programming > Object Oriented Programming anyway

              Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

              R 1 Reply Last reply
              0
              • H honey the codewitch

                I use the C runtimes with C++ language features on embedded. I avoid the STL and most of the C++ standard runtimes. Why? For the exact reasons you're running into - the C runtimes in general are far more consistent platform to platform. Furthermore, The STL is not set up to use the heap responsibly on constrained systems. You will get heap frag and eventual crashes without creating your own custom allocators for everything.

                Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                M Offline
                M Offline
                Mike Hankey
                wrote on last edited by
                #7

                honey the codewitch wrote:

                I avoid the STL and most of the C++ standard runtimes.

                Ditto I ran into problems because of basic stupidity on my part and trying to do something that I hadn't done before. Responsible memory/resource management is crucial in all embedded languages. I generally don't do dynamic memory allocation, just instantiate classes once. When I do need to do dynamic memory allocation I attempt to allocate blocks that are the same size to reduce fragmentation. When I can't do that I am very cautious to destroy when done with. You can shoot just as big a hole in your foot using C as C++!

                A home without books is a body without soul. Marcus Tullius Cicero PartsBin an Electronics Part Organizer - Release Version 1.4.0 (Many new features) JaxCoder.com Latest Article: EventAggregator

                H 1 Reply Last reply
                0
                • M Mike Hankey

                  honey the codewitch wrote:

                  I avoid the STL and most of the C++ standard runtimes.

                  Ditto I ran into problems because of basic stupidity on my part and trying to do something that I hadn't done before. Responsible memory/resource management is crucial in all embedded languages. I generally don't do dynamic memory allocation, just instantiate classes once. When I do need to do dynamic memory allocation I attempt to allocate blocks that are the same size to reduce fragmentation. When I can't do that I am very cautious to destroy when done with. You can shoot just as big a hole in your foot using C as C++!

                  A home without books is a body without soul. Marcus Tullius Cicero PartsBin an Electronics Part Organizer - Release Version 1.4.0 (Many new features) JaxCoder.com Latest Article: EventAggregator

                  H Offline
                  H Offline
                  honey the codewitch
                  wrote on last edited by
                  #8

                  I guess I misunderstood some of your initial comment. I am not fully coffee'd yet. :-\

                  Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                  1 Reply Last reply
                  0
                  • OriginalGriffO OriginalGriff

                    I'm probably old fashioned, but I don't find C++ that helpful when it comes to embedded work - stick to C and assembler is my preferred route. The idea of embedded is to get the best performance out of limited resources (speed, memory and / or power) and the extra overhead of class based OOPs isn't necessarily a good idea. And it's way harder to keep an eye on memory management to ensure memory fragmentation doesn't rear its ugly head after 2 weeks of continual runtime ... :laugh:

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                    C Offline
                    C Offline
                    CPallini
                    wrote on last edited by
                    #9

                    I am on the opposite side (at work): forced to use C while I would use C++ instead. As others suggested C++ follows the Zero-overhead principle[^].

                    "In testa che avete, Signor di Ceprano?" -- Rigoletto

                    1 Reply Last reply
                    0
                    • M Mike Hankey

                      Working with an STM32 device and trying to implement program in c++. Every platform is a little different in the way it implements C++ so trying to learn the ins and outs on the STM32. Been working on a simple Timer singleton class for the past 6 hours and it's been 2 steps forward and 1 back. Should be fairly easy but there were so many gotchas that made it very frustrating.

                      A home without books is a body without soul. Marcus Tullius Cicero PartsBin an Electronics Part Organizer - Release Version 1.4.0 (Many new features) JaxCoder.com Latest Article: EventAggregator

                      C Offline
                      C Offline
                      charlieg
                      wrote on last edited by
                      #10

                      watch out for memory allocation. Project I was on 5+ years ago was burned with "new" and other items for memory allocation not being thread safe. There was a macro to define that fixed everything.

                      Charlie Gilley “Microsoft is the virus..." "the problem with socialism is that eventually you run out of other people's money"

                      1 Reply Last reply
                      0
                      • J jeron1

                        Sounds painful, but also like article material.

                        "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

                        C Offline
                        C Offline
                        Carmen Clark
                        wrote on last edited by
                        #11

                        Comments reflect a mix of humor and truth. The debugging experience can be frustrating, much like navigating the slope game tricky slopes. Social media often blurs reality; as the quote suggests, on Facebook, we're more likely to embellish, while Twitter showcases our raw feelings.

                        1 Reply Last reply
                        0
                        • H honey the codewitch

                          Forget classes. template and constexpr mean I can create faster/more efficient code in C++ than you can readily create in C. You don't have to use features that generate overhead in C++. Zero overhead C++ is a thing. Besides, Generic Programming > Object Oriented Programming anyway

                          Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                          R Offline
                          R Offline
                          Rage
                          wrote on last edited by
                          #12

                          honey the codewitch wrote:

                          classes. template

                          Aren't these almost equivalent, at some point ? Thinking in this way : https://stackoverflow.com/questions/879535/what-is-the-difference-between-a-template-class-and-a-class-template[^]

                          Do not escape reality : improve reality !

                          H 1 Reply Last reply
                          0
                          • R Rage

                            honey the codewitch wrote:

                            classes. template

                            Aren't these almost equivalent, at some point ? Thinking in this way : https://stackoverflow.com/questions/879535/what-is-the-difference-between-a-template-class-and-a-class-template[^]

                            Do not escape reality : improve reality !

                            H Offline
                            H Offline
                            honey the codewitch
                            wrote on last edited by
                            #13

                            Nah. template can be applied to functions as well as struct/class. Warning - basic implementation details: When your compiler sees a template instantiation it basically works like a mail merge for source code, but with typed inputs. It takes those inputs, and uses the template to determine what TEXTUAL output to produce. That C++ text output is then fed back to the compiler and fully parsed/compiled (some initial parsing is done on the preinstantiated template, but it's not fully processed by the compiler until instantiation). That's the functionality of the template keyword. It's a source code generator. Edit: I should add, with template you often create "throw away" types - they're never actually used at runtime, and the compiler generates no direct machine code output for them. I don't consider those to be actual structs/classes because they are never used. They are simply a way to cajole the compiler into doing things it wasn't designed for when C++ was dreamed up.

                            Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                            1 Reply Last reply
                            0
                            • J jeron1

                              Sounds painful, but also like article material.

                              "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

                              C Offline
                              C Offline
                              Carmen Clark
                              wrote on last edited by
                              #14

                              Internet vạn vật (IoT): Viễn thông đang thúc đẩy các thành phố thông minh như thế nào
                              khoảng 22 giờ trước
                              bởi Liam Smith
                              Khi các thành phố trở nên thông minh hơn, cơ sở hạ tầng viễn thông đang đóng vai trò quan trọng trong việc tạo điều kiện cho Internet vạn vật (IoT). Từ đèn giao thông thông minh đến hệ thống quản lý chất thải, các thiết bị IoT đều dựa vào kết nối internet mạnh mẽ, nhanh và độ trễ thấp để hoạt động liền mạch. Các công ty viễn thông đang đầu tư mạnh vào việc xây dựng cơ sở hạ tầng cần thiết để hỗ trợ các thiết bị này, sử dụng kết hợp 5G, cáp quang và điện toán biên để đảm bảo dữ liệu có thể được xử lý theo thời gian thực. Ví dụ, ô tô được kết nối dựa vào mạng nhanh để giao tiếp với nhau và với hệ thống giao thông để ngăn ngừa tai nạn và tối ưu hóa lưu lượng giao thông. Tương tự như vậy, các tòa nhà thông minh sử dụng cảm biến IoT để quản lý mức tiêu thụ năng lượng hiệu quả hơn. Sự gia tăng của các thành phố thông minh do IoT thúc đẩy có thể cải thiện đáng kể cuộc sống đô thị, giảm tắc nghẽn, cải thiện an toàn và giảm tác động đến môi trường. Khi số lượng thiết bị được kết nối tiếp tục tăng, vai trò của các công ty viễn thông trong việc thúc đẩy tương lai này sẽ ngày càng trở nên quan trọng hơn.

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups