Page 2 of 2

Re: Looking for advice with C++ learning

Posted: Mon Aug 19, 2019 12:49 pm
by PeterO
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 !
PeterO
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
PeterO

Re: Looking for advice with C++ learning

Posted: Mon Sep 02, 2019 7:06 am
by EmmaHathaway
Yeah, the cplusplus.com is actually good, vote it.

Re: Looking for advice with C++ learning

Posted: Tue Sep 03, 2019 9:31 am
by deepo
Exactly.
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.

/Mogens

Re: Looking for advice with C++ learning

Posted: Tue Sep 03, 2019 9:55 am
by jamesh
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.

Re: Looking for advice with C++ learning

Posted: Sat Sep 07, 2019 2:32 am
by swampdog
Really (really) terse example..

Code: Select all

#include <iostream>

using std::cout;
typedef unsigned char TINYINT;
typedef unsigned int BIGGERINT;
struct foo {
TINYINT a;
 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;
 }
};


int
main()
{foo	a(254),
	b(1),
	c(99);

 c = a + b;
cout<<(unsigned)c.a<<'\n';
 return 0;
}

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