by support »
Hi,
I tried a similar program, but instead of sending the data to a Xillybus stream, it went just to a file, so I can see what I got. My try.cc goes
- Code: Select all
#include <fstream>
int main()
{
unsigned int output32 = 0b11111111111111111111111111111111;
std::ofstream file;
file.open("file.txt");
file << output32;
file.close();
return 0;
}
So I compiled, ran it, and looked what's inside:
- Code: Select all
$ g++ -Wall -O3 try.cc -o try
$ ./try
$ hexdump -C file.txt
00000000 34 32 39 34 39 36 37 32 39 35 |4294967295|
0000000a
$ cat file.txt
4294967295
So there you have it. C++ converted the integer into a string before sending it to the standard input, so instead of sending all ones, you got the string "4294967295". Isn't it wonderful that C++ does all those nice things automatically?
Is there any reason in particular why you use C++ as opposed to plain C? My opinion about C++ is that it's for C programmers who want to entertain themselves with cool software concepts, but in the end they get bugs exactly of this type.
Regards,
Eli
Hi,
I tried a similar program, but instead of sending the data to a Xillybus stream, it went just to a file, so I can see what I got. My try.cc goes
[code]#include <fstream>
int main()
{
unsigned int output32 = 0b11111111111111111111111111111111;
std::ofstream file;
file.open("file.txt");
file << output32;
file.close();
return 0;
}[/code]
So I compiled, ran it, and looked what's inside:
[code]$ g++ -Wall -O3 try.cc -o try
$ ./try
$ hexdump -C file.txt
00000000 34 32 39 34 39 36 37 32 39 35 |4294967295|
0000000a
$ cat file.txt
4294967295[/code]
So there you have it. C++ converted the integer into a string before sending it to the standard input, so instead of sending all ones, you got the string "4294967295". Isn't it wonderful that C++ does all those nice things automatically?
Is there any reason in particular why you use C++ as opposed to plain C? My opinion about C++ is that it's for C programmers who want to entertain themselves with cool software concepts, but in the end they get bugs exactly of this type.
Regards,
Eli