[opensuse-factory] ULONG_MAX=-1
Hello. I am learning C. For current exercise I need to use the ULONG_MAX from limits.h . I have the >>current milestone of OpenSUSE<< installed. In the code I have, with nothing else in between: unsigned long int var; var=ULONG_MAX; printf("%ld",var); When executed, the last statement of the three prints out "-1" . gcc -ansi -Wall gives no output at all for this revision of the program. Though I have hardware capable of virtualization, I don't have the space to install a VM. I suspect it's a bug in OpenSUSE (maybe even quite old), so can someone, please, do quick check on a stable release of OpenSUSE, what value does the ULONG_MAX take? When I examined /usr/lib64/gcc/x86_64-suse-linux/4.8/include-fixed/limits.h and /usr/include/linux/limits.h , for me it looks like a third header with __LONG_MAX__ is needed. I have had installed the devel_basis, devel_kernel and devel_C_C++ patterns. To make it easier, here's the code to check the value: #include<stdio.h> #include<limits.h> int main (void) { unsigned long int var; var=ULONG_MAX; printf("%ld",var); return 0; } -- Marek Paśnikowski -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
Marek Paśnikowski <marekpasnikowski@marekpasnikowski.name> writes:
unsigned long int var; var=ULONG_MAX; printf("%ld",var);
When executed, the last statement of the three prints out "-1" .
This is correct. If you want to print out an unsigned integer use %u, %d expects a signed integer. Andreas. -- Andreas Schwab, SUSE Labs, schwab@suse.de GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7 "And now for something completely different." -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
On Tue, 20 Aug 2013 10:16:03 +0200 Marek Paśnikowski <marekpasnikowski@marekpasnikowski.name> wrote:
Hello. I am learning C. For current exercise I need to use the ULONG_MAX from limits.h . I have the >>current milestone of OpenSUSE<< installed. In the code I have, with nothing else in between:
unsigned long int var; var=ULONG_MAX; printf("%ld",var);
When executed, the last statement of the three prints out "-1" .
gcc -ansi -Wall gives no output at all for this revision of the program. Though I have hardware capable of virtualization, I don't have the space to install a VM. I suspect it's a bug in OpenSUSE (maybe even quite old), so can someone, please, do quick check on a stable release of OpenSUSE, what value does the ULONG_MAX take?
When I examined /usr/lib64/gcc/x86_64-suse-linux/4.8/include-fixed/limits.h and /usr/include/linux/limits.h , for me it looks like a third header with __LONG_MAX__ is needed. I have had installed the devel_basis, devel_kernel and devel_C_C++ patterns.
To make it easier, here's the code to check the value:
#include<stdio.h> #include<limits.h> int main (void) { unsigned long int var; var=ULONG_MAX; printf("%ld",var); return 0; }
Maybe this helps: #include <stdio.h> #include <limits.h> int main (void) { unsigned long var; var = ULONG_MAX; printf("%lu\n",var); return 0; } -- Robert Milasan L3 Support Engineer SUSE Linux (http://www.suse.com) email: rmilasan@suse.com GPG fingerprint: B6FE F4A8 0FA3 3040 3402 6FE7 2F64 167C 1909 6D1A -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
:( Oh my. Thank you. Eh, looks like I need to jot down another table, with all the %stuff. Sorry for apparently stupid question. -- Marek Paśnikowski -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
On Tue, 20 Aug 2013 10:29, Marek Paśnikowski <marekpasnikowski@...> wrote:
:( Oh my. Thank you. Eh, looks like I need to jot down another table, with all the %stuff. Sorry for apparently stupid question.
There is no stupid question during learning a language. But, no need to write the table yourself: CMD-LINE> man 3 printf Or, more generic "man 3 [c-function]" - Yamaban.
participants (4)
-
Andreas Schwab
-
Marek Paśnikowski
-
Robert Milasan
-
Yamaban