1. Rob printf problem.
Rob: printf does not work in Euphoria the same way as it does in "C"
Run the following in "C" ( I used both Borland and MSC )
#include <stdio.h>
main() {
printf("%d\n", -1);
printf("%d\n", 0xffffffff); // this returns -1
}
Then run the following in Euphoria
printf(1,"%d\n", -1)
printf(1,"%d\n", #FFFFFFFF) -- this does not return -1
Thanks
Bernie
2. Re: Rob printf problem.
Bernie Ryan writes:
> Run the following in "C" ( I used both Borland and MSC )
> #include <stdio.h>
> main() {
> printf("%d\n", -1);
> printf("%d\n", 0xffffffff); // this returns -1
> }
> Then run the following in Euphoria
> printf(1,"%d\n", -1)
> printf(1,"%d\n", #FFFFFFFF) -- this does not return -1
In Euphoria, hex numbers are positive unless
there's a minus sign in front.
You can "correct" the C code by using %u
(display an unsigned integer), instead of %d
(display a signed integer).
In Euphoria, you don't have to worry about
signed vs. unsigned integers. %d simply means
display an integer.
Regards,
Rob Craig
Rapid Deployment Software
http://www.RapidEuphoria.com
3. Re: Rob printf problem.
On Sat, 8 Jan 2000 15:02:54 -0500, Robert Craig <rds at ATTCANADA.NET> wrote:
>In Euphoria, hex numbers are positive unless
>there's a minus sign in front.
>
>You can "correct" the C code by using %u
>(display an unsigned integer), instead of %d
>(display a signed integer).
I am working on a new library and interfacing to other languages.
If a "C" or a assembler program is returning a minus one to Euphoria, then
how is Euphoria going to know if the returned value is a -1 or 4294967295 ?
Bernie
4. Re: Rob printf problem.
- Posted by Robert Craig <rds at ATTCANADA.NET>
Jan 08, 2000
-
Last edited Jan 09, 2000
Bernie Ryan writes:
> If a "C" or a assembler program is returning a
> minus one to Euphoria, then
> how is Euphoria going to know if the returned value
> is a -1 or 4294967295 ?
In the C case, you should declare the return type of
the C function in define_c_func() as an unsigned C type,
e.g. C_UINT, if you want 4294967295 returned, or as C_INT
if you want -1 returned.
In the machine code case, Euphoria's peek4u()
will return 4294967295 from memory,
whenever peek4s() returns -1.
The C declaration of a C function will tell you
if a signed or an unsigned value is being returned.
You will need to understand the intent of a machine
code routine when interpreting it's result.
Regards,
Rob Craig
Rapid Deployment Software
http://www.RapidEuphoria.com