Page 1 of 1

type cast voodoo

Posted: Thu Sep 09, 2021 1:42 pm
by hehimself
Hi,

could somebody please check the following code (end of post) on an Ember system? I get different results on my 2 systems. The old Debian rack with Ember-1.9 produces the expected output:

digit=0
string=07727
digit=7727
string=7728
digit=7728
and so on

My new Ubuntu rack drives me crazy with

digit=0
string=07727
digit=4055
string=4056
digit=4056
and so on

If I use as starting string "07728" it gets even better:

digit=0
string=07728
Runtime error at line 17 of script 'casting_fun.ehtml'. Error is 'Type cast failed'

Looking at different bases there seems to be a connection with the octal representation. 7727 octal is 4055 decimal. But it's not what I need or expect, especially the type cast failure . . . :-(

So, any hints to whether my machine is broken or my code or Ember are welcome.

<html>
<head>
<title>Casting fun</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

<body>
<!
$digit = 0;
$count = 0;
$string = "07727";
printf("digit=%d<br>\n", $digit);
printf("string=%s<br>\n", $string);

while ( $count < 11 )
{
$digit = (int)$string;
printf("digit=%d<br>\n", $digit);
$digit = $digit + 1;
$string = (text)$digit;
printf("string=%s<br>\n", $string);
$count = $count + 1;
}
>
</body>
</html>

Regards
Gerhard

Re: type cast voodoo

Posted: Fri Sep 10, 2021 5:58 am
by david
This works as expected with the current 2.1 release. Also, if you strip all the HTML stuff from it you can just run it as you would any "normal" script using "ember FILENAME"

As for type casting from string to integer, we just use whatever your system includes. To get an understanding have a read of

Code: Select all

man strtol

David
...