473,404 Members | 2,137 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,404 software developers and data experts.

Fully-portable version of limits.h


I was pondering over writing a fully-portable version of <limits.h(e.g.
such things as:

#define UINT_MAX ((unsigned)-1)

, when something occurred to me. Just recently on this newsgroup, I and a few
others posted code which yielded a compile-time constant specifying the
amount of bits which are set in an integer expression; then I thought about
IMAX_BITS, and wondered if this is how IMAX_BITS works? Does it just count
how many bits are set?

Is it possible in C to a write a fully-portable version of <limits.h>? I'll
start off with the easy ones:

#define CHAR_BIT (IMAX_BITS((char unsigned)-1))
#define UCHAR_MAX ((char unsigned)-1 + 0)
#define USHRT_MAX ((short unsigned)-1 + 0)
#define UINT_MAX ((unsigned)-1)
#define ULONG_MAX ((long unsigned)-1)

--

Frederick Gotham
Sep 18 '06 #1
4 1929
Frederick Gotham <fg*******@SPAM.comwrites:
Is it possible in C to a write a fully-portable version of <limits.h>? I'll
start off with the easy ones:

#define CHAR_BIT (IMAX_BITS((char unsigned)-1))
That's not conforming. CHAR_BIT must be suitable for use in an
#if directive, but constant expressions in #if directives may not
contain casts.
--
Go not to Usenet for counsel, for they will say both no and yes.
Sep 18 '06 #2
Ben Pfaff posted:
>#define CHAR_BIT (IMAX_BITS((char unsigned)-1))

That's not conforming. CHAR_BIT must be suitable for use in an
#if directive, but constant expressions in #if directives may not
contain casts.

Damn, hadn't thought of that...

--

Frederick Gotham
Sep 18 '06 #3
Frederick Gotham wrote:
Ben Pfaff posted:

>>>#define CHAR_BIT (IMAX_BITS((char unsigned)-1))

That's not conforming. CHAR_BIT must be suitable for use in an
#if directive, but constant expressions in #if directives may not
contain casts.

Damn, hadn't thought of that...
And as if that weren't enough, try writing a fully
portable replacement for INT_MIN. Extra credit: CHAR_MIN.

--
Eric Sosman
es*****@acm-dot-org.invalid
Sep 19 '06 #4
Frederick Gotham wrote:
I was pondering over writing a fully-portable version of <limits.h(e.g.
such things as:
There is no need to. It comes with the implementation.
Sep 19 '06 #5

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

Similar topics

2
by: Johnny | last post by:
Now I am running PHP in Apache on Windows platform, but I need to migrate it into linux and using IPv6 instead. So I want to know if PHP fully support IPv6. And how about the workload of this...
1
by: Stefan | last post by:
I'm installing Oracle 9ias Release 2 on Windows 2000 Advanced Server. The installation instructions say to specify a fully qualified host name for the machine. What is the definition of fully...
3
by: QINGFENG DUAN | last post by:
I have a Visual C++.NET DLL, which statically links to a C lib and is used in a windows user control written in C#. This windows user control will be hosted in IE. To do so, I have to Fully Trust...
4
by: Jim Garrison | last post by:
I know how to use the name() function to access the name of the current node. How do I get the 'fully qualified' name, consisting of the path from the root to the current node? I.e. <a> <b>...
4
by: Aashish Patil | last post by:
Hello, Is it possible to obtain the fully qualified name of a class in c#. What I am looking for is something analogous to Box.class.getName() that exists in Java. Its possible to get this by...
5
by: fc2 | last post by:
Hi I have a problem with fully qualified names. According to the C# language specification: "Every namespace and type has a fully qualified name, which uniquely identifies the namespace or...
5
by: thisis | last post by:
Hi All, Hi All, (this is not the same topic as the my previous topic) What objects/methods/properties does VBScript offer for: Assuring/guarantee/make certain that ASP/VBSCript an ELEMENT...
8
by: Jack | last post by:
Hi, I have a single class XXX residing in a namspace with the same name: XXX. I can access my class in my code just fine with: XXX.XXX.MySub() '(Note: shared sub!) But I don't want to...
7
by: Tom | last post by:
By my estimate, greater than 90% of the online doco code does not work without additional coding effort. Fully working solutions are invaluable for the student. A guru's work measured in minutes...
6
by: Vince | last post by:
Hello all, I am using Visual Basic to open a saved query and then save information in the query to an array for later use. The problem is that the same query shows different results when opened...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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...

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.