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

16-Bit char pointers valid?


I think someone posted elsewhere on the group that we must be able to
address at least 65 535 bytes in C... ? (Or something along those lines).

A 16-Bit unsigned integer type has 65 536 unique values. If our char
pointer is 16-Bit, then it too can contain 65 536 unique values. Take
away 1 for the null pointer value, and we have 65 535 unique byte
addresses.

So, at first glance, it looks like a 16-Bit char pointer is just about
sufficient to satisfy C's need for 65 535 bytes.

However, adding to the debate about:

char buffer[64];

const char * const p_null = 0;
const char * const p_over = buffer + 64;

assert( p_null == p_over );
If, hypothetically speaking, the pointer to "one past last" could NOT be
equal to the null pointer, then the addresses would have to be
distributed something like the following:

0x0000 to 0xFFFD inclusive : Valid byte addresses
0xFFFE : Pointer to "one past last"
0xFFFF : Null pointer value

The problem with this, however, is that 0x0000 to 0xFFFD inclusive
constitutes only 65 534 unique addresses... and this seems to not satisfy
C's need for 65 535 bytes.

So it seems to me that if p_over can't be equal to p_null, then char*
must be at least 17-Bit.

Any thoughts?
Jun 22 '06 #1
9 2335
>I think someone posted elsewhere on the group that we must be able to
address at least 65 535 bytes in C... ? (Or something along those lines).
Addressing at least 65,535 bytes doesn't have to mean having an array
that large.
A 16-Bit unsigned integer type has 65 536 unique values. If our char
pointer is 16-Bit, then it too can contain 65 536 unique values. Take
away 1 for the null pointer value, and we have 65 535 unique byte
addresses.

So, at first glance, it looks like a 16-Bit char pointer is just about
sufficient to satisfy C's need for 65 535 bytes.

However, adding to the debate about:

char buffer[64];

const char * const p_null = 0;
const char * const p_over = buffer + 64;

assert( p_null == p_over );
If, hypothetically speaking, the pointer to "one past last" could NOT be
equal to the null pointer, then the addresses would have to be
distributed something like the following:

0x0000 to 0xFFFD inclusive : Valid byte addresses
0xFFFE : Pointer to "one past last"
0xFFFF : Null pointer value

The problem with this, however, is that 0x0000 to 0xFFFD inclusive
constitutes only 65 534 unique addresses... and this seems to not satisfy
C's need for 65 535 bytes.
0xfffe addresses a byte distinct from all the other bytes
you mentioned.
So it seems to me that if p_over can't be equal to p_null, then char*
must be at least 17-Bit.


I disagree. p_over addresses a byte. You can't use the byte but
you can still address it.

Gordon L. Burditt
Jun 22 '06 #2
Gordon Burditt wrote:
I think someone posted elsewhere on the group that we must be able to
address at least 65 535 bytes in C... ? (Or something along those lines).


Addressing at least 65,535 bytes doesn't have to mean having an array
that large.


"65535 bytes in an object" when every object can be accessed as an
array of (unsigned) char does mean having an array that large.

(Disclaimer repeated: there is a strict reading of the standard that
disagrees with this, but using that reading, no implementation, hosted
or otherwise, is required to accept even a single strictly conforming
program, which is clearly ridiculous.)

Jun 22 '06 #3
Frederick Gotham <fg*******@SPAM.com> writes:
I think someone posted elsewhere on the group that we must be able to
address at least 65 535 bytes in C... ? (Or something along those lines).
The actual requirement is (C99 5.2.4.1):

The implementation shall be able to translate and execute at least
one program that contains at least one instance of every one of
the following limits:

...

65535 bytes in an object (in a hosted environment only)
A 16-Bit unsigned integer type has 65 536 unique values. If our char
pointer is 16-Bit, then it too can contain 65 536 unique values. Take
away 1 for the null pointer value, and we have 65 535 unique byte
addresses.
Right.
So, at first glance, it looks like a 16-Bit char pointer is just about
sufficient to satisfy C's need for 65 535 bytes.

However, adding to the debate about:

char buffer[64];

const char * const p_null = 0;
const char * const p_over = buffer + 64;

assert( p_null == p_over );
If, hypothetically speaking, the pointer to "one past last" could NOT be
equal to the null pointer, then the addresses would have to be
distributed something like the following:

0x0000 to 0xFFFD inclusive : Valid byte addresses
0xFFFE : Pointer to "one past last"
0xFFFF : Null pointer value

The problem with this, however, is that 0x0000 to 0xFFFD inclusive
constitutes only 65 534 unique addresses... and this seems to not satisfy
C's need for 65 535 bytes.

So it seems to me that if p_over can't be equal to p_null, then char*
must be at least 17-Bit.


Yes, if a pointer just past the end of an array cannot be null, then
you need at least 17 bits for char*.

Even if it can be null, that single object plus the null pointer takes
up all 65536 possible char* values; no other objects can exist in the
program. The single program also has to have, among other things,
4095 characters in a string literal; each character in the literal has
to have a unique address. Conceivably an implementation could cheat
if the address isn't actually used, but I don't believe an
implementation could *usefully* satisfy 5.2.4.1 with 16-bit pointers.

Note that the C90 requirement was 32768 bytes, so a conforming hosted
C90 implementation could probably get away with using 16-bit pointers
(though I don't know of any that do so).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jun 22 '06 #4
Keith Thompson wrote:
Note that the C90 requirement was 32768 bytes, so a conforming hosted
C90 implementation could probably get away with using 16-bit pointers
(though I don't know of any that do so).


I have the impression that they were thinking
of 16 bit ptrdiff_t, when they wrote that requirement.

--
pete
Jun 22 '06 #5
Keith Thompson said:
Note that the C90 requirement was 32768 bytes


32767.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jun 22 '06 #6
Richard Heathfield <in*****@invalid.invalid> writes:
Keith Thompson said:
Note that the C90 requirement was 32768 bytes


32767.


Obviously I was expressing the number in base 9.99992154311217.

Sheesh!

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jun 22 '06 #7
Keith Thompson wrote:
Frederick Gotham <fg*******@SPAM.com> writes:
I think someone posted elsewhere on the group that we must be able to
address at least 65 535 bytes in C... ? (Or something along those lines).


The actual requirement is (C99 5.2.4.1):

The implementation shall be able to translate and execute at least
one program that contains at least one instance of every one of
the following limits:

...

65535 bytes in an object (in a hosted environment only)
A 16-Bit unsigned integer type has 65 536 unique values. If our char
pointer is 16-Bit, then it too can contain 65 536 unique values. Take
away 1 for the null pointer value, and we have 65 535 unique byte
addresses.


Right.
So, at first glance, it looks like a 16-Bit char pointer is just about
sufficient to satisfy C's need for 65 535 bytes.

However, adding to the debate about:

char buffer[64];

const char * const p_null = 0;
const char * const p_over = buffer + 64;

assert( p_null == p_over );
If, hypothetically speaking, the pointer to "one past last" could NOT be
equal to the null pointer, then the addresses would have to be
distributed something like the following:

0x0000 to 0xFFFD inclusive : Valid byte addresses
0xFFFE : Pointer to "one past last"
0xFFFF : Null pointer value

The problem with this, however, is that 0x0000 to 0xFFFD inclusive
constitutes only 65 534 unique addresses... and this seems to not satisfy
C's need for 65 535 bytes.

So it seems to me that if p_over can't be equal to p_null, then char*
must be at least 17-Bit.


Yes, if a pointer just past the end of an array cannot be null, then
you need at least 17 bits for char*.

Even if it can be null, that single object plus the null pointer takes
up all 65536 possible char* values; no other objects can exist in the
program. The single program also has to have, among other things,
4095 characters in a string literal; each character in the literal has
to have a unique address. Conceivably an implementation could cheat
if the address isn't actually used, but I don't believe an
implementation could *usefully* satisfy 5.2.4.1 with 16-bit pointers.


A string literal can be used in the initialiser for the object of 65535
bytes, if it is an array of char, or is a struct containing such an
array. This does not require cheating, and does not require more than
65536 distinct pointer values.

Jun 23 '06 #8
"Harald van Dijk" <tr*****@gmail.com> writes:
Keith Thompson wrote:

[...]
Yes, if a pointer just past the end of an array cannot be null, then
you need at least 17 bits for char*.

Even if it can be null, that single object plus the null pointer takes
up all 65536 possible char* values; no other objects can exist in the
program. The single program also has to have, among other things,
4095 characters in a string literal; each character in the literal has
to have a unique address. Conceivably an implementation could cheat
if the address isn't actually used, but I don't believe an
implementation could *usefully* satisfy 5.2.4.1 with 16-bit pointers.


A string literal can be used in the initialiser for the object of 65535
bytes, if it is an array of char, or is a struct containing such an
array. This does not require cheating, and does not require more than
65536 distinct pointer values.


5.2.4.1 also requires 127 parameters in one function definition and
127 arguments in one function call. Each parameter needs a distinct
address if the function is called.

It still *might* be possible to conform with 16-bit pointers, but it
would be a serious challenge, and hardly worth the effort (unless you
want to submit the first entry to an International Obfuscated C
Compiler Contest).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jun 23 '06 #9
Keith Thompson wrote:
"Harald van Dijk" <tr*****@gmail.com> writes:
Keith Thompson wrote: [...]
Yes, if a pointer just past the end of an array cannot be null, then
you need at least 17 bits for char*.

Even if it can be null, that single object plus the null pointer takes
up all 65536 possible char* values; no other objects can exist in the
program. The single program also has to have, among other things,
4095 characters in a string literal; each character in the literal has
to have a unique address. Conceivably an implementation could cheat
if the address isn't actually used, but I don't believe an
implementation could *usefully* satisfy 5.2.4.1 with 16-bit pointers.


A string literal can be used in the initialiser for the object of 65535
bytes, if it is an array of char, or is a struct containing such an
array. This does not require cheating, and does not require more than
65536 distinct pointer values.


5.2.4.1 also requires 127 parameters in one function definition and
127 arguments in one function call. Each parameter needs a distinct
address if the function is called.


I thought that wasn't necessary if they could be declared with
"register", but I now realise that would apply to the 65535 bytes as
well. There are some other ways around this, but I think they all rely
on compiler extensions, which (to me) makes them cheats.
It still *might* be possible to conform with 16-bit pointers, but it
would be a serious challenge, and hardly worth the effort (unless you
want to submit the first entry to an International Obfuscated C
Compiler Contest).


Definitely not worth the effort if the implementation can simply be
called a freestanding one, which happens to support most of what is
required of hosted implementations.

Jun 23 '06 #10

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

Similar topics

0
by: Andreas Falck | last post by:
Hi, I ran the code below on two different versions, 4.0.14 and 4.0.16 respectively, both running RH 7.3 on intel. In version mysql server version 4.0.14 the SELECT privelege suffices for...
38
by: Haines Brown | last post by:
I'm having trouble finding the character entity for the French abbreviation for "number" (capital N followed by a small supercript o, period). My references are not listing it. Where would I...
16
by: lawrence | last post by:
I was told in another newsgroup (about XML, I was wondering how to control user input) that most modern browsers empower the designer to cast the user created input to a particular character...
12
by: Olaf Baeyens | last post by:
I am porting some of my buffer class code for C++ to C#. This C++ class allocates a block of memory using m_pBuffer=new BYTE; But since the class is also used for pointers for funtions that uses...
23
by: Steven T. Hatton | last post by:
This is one of the first obstacles I encountered when getting started with C++. I found that everybody had their own idea of what a string is. There was std::string, QString, xercesc::XMLString,...
1
by: Zhongjian Lu | last post by:
Hi Guys, I was processing a UTF-16 coded file with BOM and was not aware of the codecs package at first. I wrote the following code: ===== Code 1============================ for i in...
22
by: Albert Oppenheimer | last post by:
I thought my program had to be caught in a loop, and cancelled it through the task manager. It took about one second in Java, but re-implemented in C, it had already run over one minute. I set...
3
by: stil | last post by:
hi, i've got a little problem with encoding in UTF_16. i create my document, giving him to my writer to write in a string, when i set an encoding in UTF-8: DOMWriter* L_poWriter =...
7
by: Jimmy Shaw | last post by:
Hi everybody, Is there any SIMPLE way to convert from UTF-16 to UTF-32? I may be mixed up, but is it possible that all UTF-16 "code points" that are 16 bits long appear just the same in UTF-32,...
0
by: Bill Wordsworth | last post by:
This is what I have done so far: In Stored Procedure, I set- * v_xml OUT NVARCHAR2 * v_xml := '<?xml version="1.0" encoding="UTF-16" ?>...'; -- without any chr(10) newline In Application, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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.