473,411 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

limits.h question

Hey, I'm learning about the limits header, and I don't understand one
snippit of code. If I code:

#include <limits.h>
#include <stdio.h>
int main()
{
printf("Smallest signed long long: %lld\n", LLONG_MIN);
return 0;
}
I get the output:
Smallest signed long long: 0

Why is this? I even check in my limits.h file, where I see:
#define LLONG_MIN 0x8000000000000000 /*minimum signed __int64 value */

Why won't it print the limit?
Nov 14 '05 #1
16 6416
By the way...this might be off topic, but if i code the same thing in c++
with cout << it works ok...weird
"Mark Bruno" <ya*************@yahoo.com> wrote in message
news:3M********************@comcast.com...
Hey, I'm learning about the limits header, and I don't understand one
snippit of code. If I code:

#include <limits.h>
#include <stdio.h>
int main()
{
printf("Smallest signed long long: %lld\n", LLONG_MIN);
return 0;
}
I get the output:
Smallest signed long long: 0

Why is this? I even check in my limits.h file, where I see:
#define LLONG_MIN 0x8000000000000000 /*minimum signed __int64 value */
Why won't it print the limit?

Nov 14 '05 #2
Mark Bruno wrote:
Hey, I'm learning about the limits header, and I don't understand one
snippit of code. If I code:

#include <limits.h>
#include <stdio.h>
int main()
{
printf("Smallest signed long long: %lld\n", LLONG_MIN);
return 0;
}
I get the output:
Smallest signed long long: 0

Why is this? I even check in my limits.h file, where I see:
#define LLONG_MIN 0x8000000000000000 /*minimum signed __int64 value */

Why won't it print the limit?


It would seem that you are using a <limits.h> not appropriate for your
compiler. Make sure that you don't have a mismatch. For comparison, I get
for my implementation:

#include <limits.h>
#include <stdio.h>
int main(void)
{
printf("Smallest signed long long: %lld\n", LLONG_MIN);
printf("Smallest signed long: %ld\n", LONG_MIN);
printf("Smallest signed int: %d\n", INT_MIN);
printf("Smallest signed short: %hd\n", SHRT_MIN);
printf("Smallest signed char: %d\n", SCHAR_MIN);
printf("Largest signed long long: %lld\n", LLONG_MAX);
printf("Largest unsigned long long: %llu\n", ULLONG_MAX);
printf("Largest signed long: %ld\n", LONG_MAX);
printf("Largest unsigned long: %lu\n", ULONG_MAX);
printf("Largest signed int: %d\n", INT_MAX);
printf("Largest unsigned int: %u\n", UINT_MAX);
printf("Largest signed short: %hd\n", SHRT_MAX);
printf("Largest unsigned short: %hu\n", USHRT_MAX);
printf("Largest signed char: %d\n", SCHAR_MAX);
printf("Largest unsigned char: %u\n", UCHAR_MAX);
return 0;
}

Smallest signed long long: -9223372036854775808
Smallest signed long: -2147483648
Smallest signed int: -2147483648
Smallest signed short: -32768
Smallest signed char: -128
Largest signed long long: 9223372036854775807
Largest unsigned long long: 18446744073709551615
Largest signed long: 2147483647
Largest unsigned long: 4294967295
Largest signed int: 2147483647
Largest unsigned int: 4294967295
Largest signed short: 32767
Largest unsigned short: 65535
Largest signed char: 127
Largest unsigned char: 255


--
Martin Ambuhl

Nov 14 '05 #3
I'm using MS Visual C++ 7.1 (.net 2003), with all the appropriate headers.
Anyone with MSVC++7.1 out there who can vouch for this bug?
"Martin Ambuhl" <ma*****@earthlink.net> wrote in message
news:xF******************@newsread3.news.atl.earth link.net...
Mark Bruno wrote:
Hey, I'm learning about the limits header, and I don't understand one
snippit of code. If I code:

#include <limits.h>
#include <stdio.h>
int main()
{
printf("Smallest signed long long: %lld\n", LLONG_MIN);
return 0;
}
I get the output:
Smallest signed long long: 0

Why is this? I even check in my limits.h file, where I see:
#define LLONG_MIN 0x8000000000000000 /*minimum signed __int64 value */
Why won't it print the limit?


It would seem that you are using a <limits.h> not appropriate for your
compiler. Make sure that you don't have a mismatch. For comparison, I get
for my implementation:

#include <limits.h>
#include <stdio.h>
int main(void)
{
printf("Smallest signed long long: %lld\n", LLONG_MIN);
printf("Smallest signed long: %ld\n", LONG_MIN);
printf("Smallest signed int: %d\n", INT_MIN);
printf("Smallest signed short: %hd\n", SHRT_MIN);
printf("Smallest signed char: %d\n", SCHAR_MIN);
printf("Largest signed long long: %lld\n", LLONG_MAX);
printf("Largest unsigned long long: %llu\n", ULLONG_MAX);
printf("Largest signed long: %ld\n", LONG_MAX);
printf("Largest unsigned long: %lu\n", ULONG_MAX);
printf("Largest signed int: %d\n", INT_MAX);
printf("Largest unsigned int: %u\n", UINT_MAX);
printf("Largest signed short: %hd\n", SHRT_MAX);
printf("Largest unsigned short: %hu\n", USHRT_MAX);
printf("Largest signed char: %d\n", SCHAR_MAX);
printf("Largest unsigned char: %u\n", UCHAR_MAX);
return 0;
}

Smallest signed long long: -9223372036854775808
Smallest signed long: -2147483648
Smallest signed int: -2147483648
Smallest signed short: -32768
Smallest signed char: -128
Largest signed long long: 9223372036854775807
Largest unsigned long long: 18446744073709551615
Largest signed long: 2147483647
Largest unsigned long: 4294967295
Largest signed int: 2147483647
Largest unsigned int: 4294967295
Largest signed short: 32767
Largest unsigned short: 65535
Largest signed char: 127
Largest unsigned char: 255


--
Martin Ambuhl

Nov 14 '05 #4
I think this stems from VC++'s non C99 compliance, so some long long
features are implemented, but some (such as %lld in printf and scanf)
aren't.
"Mark Bruno" <ya*************@yahoo.com> wrote in message
news:yM********************@comcast.com...
I'm using MS Visual C++ 7.1 (.net 2003), with all the appropriate headers.
Anyone with MSVC++7.1 out there who can vouch for this bug?
"Martin Ambuhl" <ma*****@earthlink.net> wrote in message
news:xF******************@newsread3.news.atl.earth link.net...
Mark Bruno wrote:
Hey, I'm learning about the limits header, and I don't understand one
snippit of code. If I code:

#include <limits.h>
#include <stdio.h>
int main()
{
printf("Smallest signed long long: %lld\n", LLONG_MIN);
return 0;
}
I get the output:
Smallest signed long long: 0

Why is this? I even check in my limits.h file, where I see:
#define LLONG_MIN 0x8000000000000000 /*minimum signed __int64
value
*/
Why won't it print the limit?


It would seem that you are using a <limits.h> not appropriate for your
compiler. Make sure that you don't have a mismatch. For comparison, I get for my implementation:

#include <limits.h>
#include <stdio.h>
int main(void)
{
printf("Smallest signed long long: %lld\n", LLONG_MIN);
printf("Smallest signed long: %ld\n", LONG_MIN);
printf("Smallest signed int: %d\n", INT_MIN);
printf("Smallest signed short: %hd\n", SHRT_MIN);
printf("Smallest signed char: %d\n", SCHAR_MIN);
printf("Largest signed long long: %lld\n", LLONG_MAX);
printf("Largest unsigned long long: %llu\n", ULLONG_MAX);
printf("Largest signed long: %ld\n", LONG_MAX);
printf("Largest unsigned long: %lu\n", ULONG_MAX);
printf("Largest signed int: %d\n", INT_MAX);
printf("Largest unsigned int: %u\n", UINT_MAX);
printf("Largest signed short: %hd\n", SHRT_MAX);
printf("Largest unsigned short: %hu\n", USHRT_MAX);
printf("Largest signed char: %d\n", SCHAR_MAX);
printf("Largest unsigned char: %u\n", UCHAR_MAX);
return 0;
}

Smallest signed long long: -9223372036854775808
Smallest signed long: -2147483648
Smallest signed int: -2147483648
Smallest signed short: -32768
Smallest signed char: -128
Largest signed long long: 9223372036854775807
Largest unsigned long long: 18446744073709551615
Largest signed long: 2147483647
Largest unsigned long: 4294967295
Largest signed int: 2147483647
Largest unsigned int: 4294967295
Largest signed short: 32767
Largest unsigned short: 65535
Largest signed char: 127
Largest unsigned char: 255


--
Martin Ambuhl


Nov 14 '05 #5
Mark Bruno wrote:
I think this stems from VC++'s non C99 compliance, so some long long
features are implemented, but some (such as %lld in printf and scanf)
aren't.


Please stop top-posting. It's rude.

My understanding is that Microsoft has not made, and has no interest in
making their compiler C99-compliant.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Nov 14 '05 #6
> Mark Bruno wrote:
I think this stems from VC++'s non C99 compliance, so some long long
features are implemented, but some (such as %lld in printf and scanf)
aren't.


<OT>
I may be wrong, but I think that on Windows systems, printf is
implemented in msvc.dll (along with most if not all of the C standard
library). This is probably where the problem lies. You could check
whether there's an updated version with proper C99 support.

I tried a little test:

$ gcc -v
Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/3.3.1/specs
Configured with: /GCC/gcc-3.3.1-3/configure --with-gcc --with-gnu-ld
--with-gnu-as --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc
--libdir=/usr/lib --libexecdir=/usr/sbin --mandir=/usr/share/man
--infodir=/usr/share/info
--enable-languages=c,ada,c++,f77,pascal,java,objc --enable-libgcj
--enable-threads=posix --with-system-zlib --enable-nls
--without-included-gettext --enable-interpreter --enable-sjlj-exceptions
--disable-version-specific-runtime-libs --enable-shared
--disable-win32-registry --enable-java-gc=boehm
--disable-hash-synchronization --verbose --target=i686-pc-cygwin
--host=i686-pc-cygwin --build=i686-pc-cygwin
Thread model: posix
gcc version 3.3.1 (cygming special)
$ cat fun.c
#include <stdio.h>
#include <limits.h>

int main(void)
{
printf("LLONG_MAX: %lld\n", LLONG_MAX);
printf("LLONG_MIN: %lld\n", LLONG_MIN);

return 0;
}
$ gcc -W -Wall -std=c99 -pedantic-errors fun.c -o fun.exe
$ ./fun
LLONG_MAX: 9223372036854775807
LLONG_MIN: -9223372036854775808
$ gcc -W -Wall -std=c99 -pedantic-errors -mno-cygwin fun.c -o fun.exe
$ ./fun
LLONG_MAX: -1
LLONG_MIN: 0
When compiled with -mno-cygwin (which forces gcc to link against the
normal Windows libraries instead of the Cygwin unix-like libraries) I
see the same thing you do, probably because it's using the exact same
library (msvc.dll).
</OT>
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Nov 14 '05 #7
Kevin Goodsell wrote:
Mark Bruno wrote:
I think this stems from VC++'s non C99 compliance, so some long long
features are implemented, but some (such as %lld in printf and scanf)
aren't.

<OT>
I may be wrong, but I think that on Windows systems, printf is
implemented in msvc.dll


I think that should have been msvcrt.dll.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Nov 14 '05 #8
What's top posting? How do I stop it?
"Kevin Goodsell" <us*********************@neverbox.com> wrote in message
news:Le******************@newsread1.news.pas.earth link.net...
Kevin Goodsell wrote:
Mark Bruno wrote:

I think this stems from VC++'s non C99 compliance, so some long long
features are implemented, but some (such as %lld in printf and scanf)
aren't.

<OT>
I may be wrong, but I think that on Windows systems, printf is
implemented in msvc.dll


I think that should have been msvcrt.dll.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Nov 14 '05 #9
"Mark Bruno" <ya*************@yahoo.com> writes:
Hey, I'm learning about the limits header, and I don't understand one
snippit of code. If I code:

#include <limits.h>
#include <stdio.h>
int main()
{
printf("Smallest signed long long: %lld\n", LLONG_MIN);
return 0;
}
I get the output:
Smallest signed long long: 0

Why is this? I even check in my limits.h file, where I see:
#define LLONG_MIN 0x8000000000000000 /*minimum signed __int64 value */

Why won't it print the limit?


I don't believe 0x8000000000000000 is a legal definition for
LLONG_MIN, even if it happens to have the same bit pattern.
(But I suspect the real problem is that your printf() either
doesn't implement %lld, or doesn't implement it correctly.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
(Note new e-mail address)
Nov 14 '05 #10
On Sat, 27 Dec 2003 05:29:23 GMT, Keith Thompson <ks***@mib.org> wrote
in comp.lang.c:
"Mark Bruno" <ya*************@yahoo.com> writes:
Hey, I'm learning about the limits header, and I don't understand one
snippit of code. If I code:

#include <limits.h>
#include <stdio.h>
int main()
{
printf("Smallest signed long long: %lld\n", LLONG_MIN);
return 0;
}
I get the output:
Smallest signed long long: 0

Why is this? I even check in my limits.h file, where I see:
#define LLONG_MIN 0x8000000000000000 /*minimum signed __int64 value */

Why won't it print the limit?


I don't believe 0x8000000000000000 is a legal definition for


Why not?

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 14 '05 #11
"Mark Bruno" <ya*************@yahoo.com> wrote in
news:XP********************@comcast.com on Fri 26 Dec 2003 09:28:14p:
What's top posting? How do I stop it?


You just top-posted.

Here's an example of why you shouldn't do it.

A: It's self-explanatory.
Q: Why is it rude?
A: It's posting your reply above the post it's in response to.
Q: What is top-posting?

You don't do it by doing like I'm doing now: Put your reply below what you
are quoting. Snipping what you aren't responding to is also nice.

Nov 14 '05 #12
"Mark Bruno" <ya*************@yahoo.com> wrote in message
news:3M********************@comcast.com...
Hey, I'm learning about the limits header, and I don't understand one
snippit of code. If I code:

#include <limits.h>
#include <stdio.h>
int main()
{
printf("Smallest signed long long: %lld\n", LLONG_MIN);
return 0;
}
I get the output:
Smallest signed long long: 0

Why is this? I even check in my limits.h file, where I see:
#define LLONG_MIN 0x8000000000000000 /*minimum signed __int64 value */
Why won't it print the limit?


I have VC7.1 too and I'm seeing the same.
I guess you can't rely on VC implementing C99 features.

The following code:
printf("%llu\n", ULLONG_MAX); will print UINT_MAX.

Pretty stupid of MS considering that it does recognize the long long format
strings and they have had the __int64 type for years.

This works with VC for instance.
printf("%I64d\n", LLONG_MIN);

All they had to do was to let %lld do the same as %I64d
Nov 14 '05 #13
Jack Klein wrote:

On Sat, 27 Dec 2003 05:29:23 GMT, Keith Thompson <ks***@mib.org> wrote
in comp.lang.c:
"Mark Bruno" <ya*************@yahoo.com> writes:
Hey, I'm learning about the limits header, and I don't understand one
snippit of code. If I code:

#include <limits.h>
#include <stdio.h>
int main()
{
printf("Smallest signed long long: %lld\n", LLONG_MIN);
return 0;
}
I get the output:
Smallest signed long long: 0

Why is this? I even check in my limits.h file, where I see:
#define LLONG_MIN 0x8000000000000000
/*minimum signed __int64 value */

Why won't it print the limit?


I don't believe 0x8000000000000000 is a legal definition for


Why not?


Because, in C99, with few exceptions, the constants in limits.h,
have to have the same type as the type to which they apply.
LLONG_MIN, even if it happens to have the same bit pattern.


--
pete
Nov 14 '05 #14
"Jack Klein" <ja*******@spamcop.net> wrote in message
news:i0********************************@4ax.com...
On Sat, 27 Dec 2003 05:29:23 GMT, Keith Thompson <ks***@mib.org> wrote
in comp.lang.c:
"Mark Bruno" <ya*************@yahoo.com> writes:
Hey, I'm learning about the limits header, and I don't understand one
snippit of code. If I code:

#include <limits.h>
#include <stdio.h>
int main()
{
printf("Smallest signed long long: %lld\n", LLONG_MIN);
return 0;
}
I get the output:
Smallest signed long long: 0

Why is this? I even check in my limits.h file, where I see:
#define LLONG_MIN 0x8000000000000000 /*minimum signed __int64 value */
Why won't it print the limit?


I don't believe 0x8000000000000000 is a legal definition for [LLONG_MIN]


Why not?


Because, for conformance with C99, such a constant would probably have the
wrong type. Assuming that the given value is too large to actually be a
valid (signed) long long, then it has type unsigned long long according to
6.4.4.1p5, and it would then violate 5.2.4.2.1p1.

As a test, I'd try...

printf("%lld\n", (long long) (LLONG_MIN / 2));

--
Peter
Nov 14 '05 #15
pete wrote:
Jack Klein wrote:
Keith Thompson <ks***@mib.org> wrote
"Mark Bruno" <ya*************@yahoo.com> writes:

> Hey, I'm learning about the limits header, and I don't
> understand one snippit of code. If I code:
>
> #include <limits.h>
> #include <stdio.h>
> int main()
> {
> printf("Smallest signed long long: %lld\n", LLONG_MIN);
> return 0;
> }
> I get the output:
> Smallest signed long long: 0
>
> Why is this? I even check in my limits.h file, where I see:
> #define LLONG_MIN 0x8000000000000000
> /*minimum signed __int64 value */
>
> Why won't it print the limit?

I don't believe 0x8000000000000000 is a legal definition for


Why not?


Because, in C99, with few exceptions, the constants in limits.h,
have to have the same type as the type to which they apply.


What is 0x80.....0? It is an unsigned long long, probably 1
greater than LLONG_MAX. When read as a long long by the printf
code an overflow and undefined behavior results. This is why you
will see such constructs (for 2's complement machines) as:

#define INT_MIN (-INT_MAX - 1)

in limits.h. Great care needs to be taken in the printf (or
equivalent code) to handle these extreme values correctly.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #16
On Sat, 27 Dec 2003 12:02:34 GMT, pete <pf*****@mindspring.com> wrote
in comp.lang.c:
Jack Klein wrote:

On Sat, 27 Dec 2003 05:29:23 GMT, Keith Thompson <ks***@mib.org> wrote
in comp.lang.c:
"Mark Bruno" <ya*************@yahoo.com> writes:
> Hey, I'm learning about the limits header, and I don't understand one
> snippit of code. If I code:
>
> #include <limits.h>
> #include <stdio.h>
> int main()
> {
> printf("Smallest signed long long: %lld\n", LLONG_MIN);
> return 0;
> }
> I get the output:
> Smallest signed long long: 0
>
> Why is this? I even check in my limits.h file, where I see:
> #define LLONG_MIN 0x8000000000000000
> /*minimum signed __int64 value */
>
> Why won't it print the limit?

I don't believe 0x8000000000000000 is a legal definition for


Why not?


Because, in C99, with few exceptions, the constants in limits.h,
have to have the same type as the type to which they apply.
LLONG_MIN, even if it happens to have the same bit pattern.


You're absolutely right, I just missed this completely. Thanks for
the correction.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 14 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: Maurice LING | last post by:
Hi, I think I've hit a system limit in python when I try to construct a list of 200,000 elements. My error is malloc: vm_allocate (size = 2400256) failed...... Just wondering is this...
1
by: Alan J. Flavell | last post by:
What are the theoretical and practical limits on the length of a GET query string, currently? Strange to say, I found this rather simple question hard to answer, possibly because of searching...
37
by: Carol Depore | last post by:
How do I determine the maximum array size? For example, int a works, but a does not (run time error). Thank you.
2
by: blaat | last post by:
Hey, I'm learning about the limits header, and I don't understand one snippit of code. If I code: #include <limits.h> #include <stdio.h> int main() { printf("Smallest signed long long:...
7
by: weg22 | last post by:
Hi all, I need to impose maximum and minimum numerical limits on a textbox. I'd prefer not to code these in (since I have many textboxes and the limits on each are different) and was wondering...
88
by: santosh | last post by:
Hello all, In K&R2 one exercise asks the reader to compute and print the limits for the basic integer types. This is trivial for unsigned types. But is it possible for signed types without...
7
by: copx | last post by:
Do the standards say anything about size limits for string literals (min size, max size)? I want to know this to make sure that my code is portable. The program in question is ANSI C89, but I would...
13
by: Josip | last post by:
I'm trying to limit a value stored by object (either int or float): class Limited(object): def __init__(self, value, min, max): self.min, self.max = min, max self.n = value def...
44
by: vippstar | last post by:
n1256.pdf (C99 TC3), 5.2.4.1 Translation limits p1 says: Does that mean that *any* program using an array of two or more elements other than char is allowed to be rejected by an implementation?...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.