Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » C++ language problems and code snippets » Dumb bug. Improper use of Null
Re: Improper use of Null [message #52331 is a reply to message #52318] Mon, 09 September 2019 20:23 Go to previous messageGo to previous message
Sender Ghost is currently offline  Sender Ghost
Messages: 301
Registered: November 2008
Senior Member
Hello IƱaki.

I think, there is some explanation in "U++ Core Tutorial" about int and int64 types, where Null "defined as lowest number the type can represent".

Following example may show how it works:
#include <Core/Core.h>
#include <iostream>

using namespace Upp;

CONSOLE_APP_MAIN
{
	int i = Null;
	int64 i64 = Null;
	double d = Null;
	Value v = Null;

	std::cout << "i = " << i << std::endl
		<< "i64 = " << i64 << std::endl
		<< "d = " << d << std::endl
		<< "v = " << ~AsString(v) << std::endl;

	if ((i == i64) && (i64 == d) && (d == v))
		NEVER();
	else
		Cout() << "This is how it works\n";

	Value vi = i,
		vi64 = i64,
		vd = d,
		vv = v;

	if ((vi == vi64) && (vi64 == vd) && (vd == vv))
		Cout() << "This is how it works\n";
	else
		NEVER();
}

With following results:
i = -2147483648
i64 = -9223372036854775808
d = -1e+308
v = 
This is how it works
This is how it works
where i is assigned to INT_NULL (equal to INT_MIN) and i64 is assigned to INT64_NULL (equal to INT64_MIN) values. In other words, i > i64 and int64 type may include INT_NULL (which is not equal to INT64_NULL) in its range.

I guess, possible to use Value type for intermediate Null value, e.g. to "transfer" Null value from some type to another type:
#include <Core/Core.h>

using namespace Upp;

CONSOLE_APP_MAIN
{
	int a = Null;
	int64 b = Value(a);

	if (IsNull(b))
		Cout() << "I wanted this\n";
	else
		Cout() << "Oh no!\n";
}

Other examples

[Updated on: Thu, 12 September 2019 16:45]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Nested template question
Next Topic: FP exception vs NaN
Goto Forum:
  


Current Time: Fri Apr 26 21:28:03 CEST 2024

Total time taken to generate the page: 0.02697 seconds