I love this project very very much, although we are using Ubuntu to debug, but I prefer to debug in Windows first.
In ubuntu 64bit, the size of long is 8 byte, however in windows it's 4 bytes.
I have no problem to use latest C standard. But our University say due to industrial requests, they need students practice in c89 / ansi.
Here is the conflict, if I were to use "ansi" flag with gcc in windows, I am not able to use the datatype of "long long". In that case printing a 8byte number like long of 9223372036854775807 would be an issue.
Can this project consider to switch long to be 8 byte please? That will make more sense as Java long is 8byte. Else if there is int already why would there be a datatype called as long right?
Plus I repeat again, in "ansi" standard, there is no "long long" datatype.
For now, if I were to count the number repeatedly and print a huge integer like 9223372036854775807 for example a task like counting factorial, what can I do? I wonder how the people in the past count it. Please don't suggest me a big integer library, that would be counted as collusion.
to addons, c89 / ansi don't have stdint.h from what I google.
And printf didn't support %llu as well for c89 / ansi
Last edit: doulc 2021-02-05
Hate to break it to you:
The long integer type is compiler defined of at least 32 bit. Windows is defining the width here. gcc yses it for compatibility. long long was introduced as minimum 64 bit in c99. C purposely defined only minimum sizes so the compiler could choose the most efficient size for the architecture. all I am guaranteed in c89 is minimums (programming to tge minimums/least common denominator.
C89 didn't define %llu, because again, long long didn't exist
My suggestion is to move to a more recent standard revision like C99 (which has stdint, long long, etc) or educate whomever is creating the C89 requirements on what "compiler defined" and "platform ABI" means. uou know, like actually reading and understanding the front matter of a standard.
Last edit: Doug Semler 2021-02-05
it is not up to me to argue with University standard. I would use the latest C Standard if it's my own choice, why would I use outdated one. But like I said, it's not decided by me.
I didn't get it, Can't Mingw do something like this? Use own library than Windows one so it unify linux and windows platform for printf scanf and Long. So it is not restricted https://code.google.com/archive/p/msinttypes/
Not going to happen, you'll break every single thing out there. You're stuck then. Microsoft decided when it created its 64 bit ABI that long would remain 32 bits for idiotic programmers that made the assumption. Therefore gcc kept that ABI restriction a LONG time ago.
You have three choices if you insist on using Wndows:
1) Update the standard requirement.
2) Use non standard compiler extensions on 64 bit windows.
3) Use C89 and understand the platform differences, and things newer than that.
You really need to understand, "compiler defined" doesn't mean "all gccs of a version on all platforms" but how a specific compiler and version creates for a specific target platform.
what do you mean non standard compiler extensions ?
Things defined by gcc that are not defined by the version of the standard being used. e.g. https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html
but that is pointless, I will need to change the code when I bring it back to linux to debug.
My laptop only got 8gb ram, running vm is not very smooth.
Booting to linux is not an option for me either, entering bios to boot is not a pleasant experience. And my graphic card is not supported by linux, nvidia issue so it is just pain working in linux environment.
You're joking right? You propose a fundamental change in something that has worked a particular way for over a decade because...reasons?
Dual boot is not difficult at ALL to set up. what are you talking about going to BIOS?
I gave you options, but Dual boot is probably your best. This is not a standards issue, the compiler conforms to the standard. Windows and Linux have different fundamental ABIs.
Besides, this would be handled by the gcc and/or binutils folks and they'll laugh at you.
how about the people who use ansi standard? They sure met this problem also right?
Correct me if I'm wrong, windows 10 security system don't allow you to dual boot linux. The last time is I'm booting it from external hard disk.
what problem? long is defined by the standard as greater than or equal to 32 and greater than or equal to int. It can store 32 bit numbers portably. 64 bit long long wasn't introduced until C99, gcc allows it as a non standard extension for c89, hence the warning. Linux 64 bit conforms because long is 64 bit gteq to 32. Windows 64 bit conforms because long is 32, gteq 32 bit. I don't see the issue here. Get it out of your head that standards exactly specify everything; sometimes, such as in this case, they specify minimums to be conformant. I have used several architectures where int is 16 bit, but need to do 32 bit computations so have to ensure i specify long in those cases. Or there are architectures created after the standard was defined.
And um, just google Ubuntu dual boot Windows 10.
You have to disable secure boot if you want dual boot, that is not a solution consider it compromise your safety.
Nah it's not possible long 64bit is only introduced in c99.
It can't be possible a datatype such as long exist for no reason when there is already integer.
Isn't it's strange int size and functionality is same as long, and both is 4 bytes? That can't be right, in c89 long is 8 byte in linux, I am sure for that, else how people calculate huge number like counting factorial, it's definitely not only introduce in c99.
Last edit: doulc 2021-02-06
secure boot is a false sense of security, dude. You have a BIOS password then? You're paranoid, all that stuff requires physical access to the machine, and if that happens, you've already lost. Secure boot is a requirement for the little Windows sticker. It was a way for Microsoft to force OEMs to only allow Windows to boot (the spec even has a provision that OEMs don't have to provide a method to disable it). Ubuntu 12 I believe has a boot loader with a secure boot key.
What? int is defined as greater than or equal to 16bits. long is defined as greater than or equal to 32 bits (and also greater than or equal to int).
int is intended to be the word size of the target machine. long is meant to be a portable method of storing a 32 bit value. Microsoft decided for backward compaibility reasons,to keep both int and long as 32 bits in its 64 bit compilers, and gcc followed suit. I've been doing this 30+ years (when K&R syntax was used) trust me, we survived. Go read the standard . Like I said, int isn't always 32 bits. GET THAT OUT OF YOUR HEAD. There are several microprocessors I have worked with with 16 bit ints. One of the reasons the intptr_t was introduced as well.
Here's an idea, since a double can represent integral values exactly and contiguously to a 53bits, you could maybe use that to store the result.
Why do I suddenly feel like I'm doing your homework for you?
you underrated secure boot. I think it is use to prevent malware as well?
read carefully perhaps? c89 standards don't have datatype to hold integer datatype of 16byte.
float is not precise for comparison
you call that as doing my homework? That is not helpful at all
Closed, this will never happen, the win32 ABI defines long as 32bit for both 32bit mode and 64bit mode and will only change if you convince Microsoft to do that.