User avatar
Posts: 5958
Joined: Sun Jul 22, 2012 4:14 pm

Re: Looking for advice with C++ learning

Mon Aug 19, 2019 12:49 pm

jahboater wrote:
Mon Aug 19, 2019 12:30 pm
PeterO wrote:
Mon Aug 19, 2019 9:28 am
needs to become something like

Code: Select all

[64 bit signed integer] a [64 bit signed operator] = [64 bit signed integer] b [ignoring overflow 64 bit signed integer operator] + [64 bit signed integer] b;
I can't see that catching on !
Did you mean "checking overflow"?
I think Heater wants all integer arithmetic to be checked for overflow.
The C "+" operator ignores overflow, so the meta data needs to reflect that behaviour. If you want to catch overflows the meta data would need to say so.

Of course this means you are effectively redeclaring every variable every time you use it
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Posts: 1
Joined: Tue Aug 27, 2019 6:11 am
Location: Shenzhen
Contact: Website Facebook

Re: Looking for advice with C++ learning

Mon Sep 02, 2019 7:06 am

Yeah, the is actually good, vote it.

Posts: 587
Joined: Sun Dec 30, 2018 8:36 pm
Location: Denmark

Re: Looking for advice with C++ learning

Tue Sep 03, 2019 9:31 am

C and C++ can achieve tremendous speeds, but there are pitfalls that coders must learn to avoid.
Specifically C comes from an era where the performance of the computers were quite limited compared with current computers. So there were no way to implement a lot of checks and still achieve acceptable performance.
The flak C and C++ receives in this thread is a mute point to me, as it has always been like that. Most are called features, not bugs :)
Anyways - a lot of stuff is still written in C and C++, so if the goal is to learn the language, please go ahead.


Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 26869
Joined: Sat Jul 30, 2011 7:41 pm

Re: Looking for advice with C++ learning

Tue Sep 03, 2019 9:55 am

C is fine, C++ is fine.

To the OP, good for you! Learn C++, start with the basics, which is C like, then move on to the more powerful classes and other differences from C. Take your time, there are lots of things to learn, you don't need to learn all of them.

And to others, please keep on topic, which is learning C++. Not promoting your favourite language, or slagging off others.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

Posts: 387
Joined: Fri Dec 04, 2015 11:22 am

Re: Looking for advice with C++ learning

Sat Sep 07, 2019 2:32 am

Really (really) terse example..

Code: Select all

#include <iostream>

using std::cout;
typedef unsigned char TINYINT;
typedef unsigned int BIGGERINT;
struct foo {
 foo(TINYINT b)
 : a(b){}
foo operator+(foo & b)
 {TINYINT	r(a+b.a);
  BIGGERINT	aa(a+b.a);
  if (aa!=r) cout<<"oops\n";
  return r;

{foo	a(254),

 c = a + b;
 return 0;

Change "a(254)" to "a(255)" and it detects overflow. :-)

Return to “C/C++”