Hi
Suppose you have somewhere
#define BOOL int
and somewhere else
typedef BOOL int;
This gives
typedef int int;
To me, this looks like a null assignment:
a = a;
Would it break something if lcc-win32 would accept that,
maybe with a warning?
Is the compiler *required* to reject that?
Microsoft MSVC: rejects it.
lcc-win32 now rejects it.
gcc (with no flags) accepts it with some warnnings.
Thanks
jacob
---
A free compiler system for windows: http://www.cs.virginia.edu/~lcc-win32
Mar 24 '06
134 9076
"Eric Sosman" <Er*********@su n.com> wrote in message
news:e0******** **@news1brm.Cen tral.Sun.COM... Does the Standard require that the 1's bit and the 2's bit of an `int' reside in the same byte?
No.
Or is the implementation free to scatter the bits of the "pure binary" representation among the different bytes as it pleases? (It must, of course, scatter the corresponding bits of signed and unsigned versions in the same way.)
Of course.
If the latter, I think there's the possibility (a perverse possibility) of a very large number of permitted "endianness es," something like
(sizeof(type) * CHAR_BIT) ! ----------------------------- (CHAR_BIT !) ** sizeof(type)
Argument: There are `sizeof(type) * CHAR_BIT' bits (value, sign, and padding) in the object, so the number of ways to permute the bits is the factorial of that quantity. But C cannot detect the arrangement of individual bits within a byte, so each byte of the object divides the number of detectably different arrangements by `CHAR_BIT!'.
But of course you can detect the order, at least in cases where padding bits
don't obscure the view. Take a look at the representation of a power of
two. If there are no padding bits, only one of the bytes has a non-zero
value, and that value is a power of two as well. And of course you can
easily detect which power of two it is.
If you assume a clear distinction between padding bits and value bits, the
correct answer is
( sizeof(type) * CHAR_BIT ) !
------------------------------------------
( number_of_paddi ng_bits ) !
But if you don't, things can get a little fuzzy. For instance, imagine an
implementation that requires that for any valid int representation, the top
two bits of its first byte must be either both set or both unset. It
doesn't matter which one you choose to consider a value bit and which one a
padding bit; but my formula counts those two choices as two distinct
combinations.
Eric Sosman wrote: Or is the implementation free to scatter the bits of the "pure binary" representation among the different bytes as it pleases? (It must, of course, scatter the corresponding bits of signed and unsigned versions in the same way.)
Wojtek Lerch wrote: Of course.
True, but ISO C also encompasses existing practice. And existing
practice throughout all of the history of mechanical computers has
been to arrange the digits of machine words in some reasonably
practical, if not completely obvious, way.
There is a limit to how far a language standard can go in covering all
implementations , and that limit is usually dictated by actual existing
implementations . ISO C does not cover trinary implementations
(as far as I can tell) for the simple reason that it does not have to.
All of which makes it entirely reasonable and possible to invent
a handful of standard macros that could adequately describe the
salient characteristics of the underlying native hardware words
used to implement the standard abstract datatypes of C.
But if there really did exist some arcane architecture that just
could not be described in this way, we can always provide a
macro like __STDC_NO_ENDIA N. I'm willing to bet, though,
that such a system could not support a conforming C
implementation in the first place.
-drt
"David R Tribble" <da***@tribble. com> wrote in message
news:11******** **************@ u72g2000cwu.goo glegroups.com.. . Eric Sosman wrote: Or is the implementation free to scatter the bits of the "pure binary" representation among the different bytes as it pleases? (It must, of course, scatter the corresponding bits of signed and unsigned versions in the same way.) Wojtek Lerch wrote: Of course.
True, but ISO C also encompasses existing practice. And existing practice throughout all of the history of mechanical computers has been to arrange the digits of machine words in some reasonably practical, if not completely obvious, way.
.... All of which makes it entirely reasonable and possible to invent a handful of standard macros that could adequately describe the salient characteristics of the underlying native hardware words used to implement the standard abstract datatypes of C.
A language standard needs to be consistent about how far it allows
conforming implementations to deviate from the currently existing practice.
It doesn't make sense for one part of the standard to allow implementations
with strange bit orders, while another part contains definitions or
requirements that turn into meaningless gibberish when applied to such
implementations . If you want to mandate existing practice in this regard,
propose adding a requirement to the standard that bans strange bit orders.
Without such a ban, you'll need to carefully pick the words that specify
your macros, to make sure that they make sense even for implementations that
use strange bit orders. Or implementations that use strings and pulleys
rather than electric current in a semiconducting material.
And keep in mind that unless the types your macros describe have no padding
bits, they're completely useless anyway. (Or do you disagree?) Perhaps you
want to propose a ban on padding bits, too?
Wojtek Lerch wrote: But of course you can detect the order, at least in cases where padding bits don't obscure the view. Take a look at the representation of a power of two. If there are no padding bits, only one of the bytes has a non-zero value, and that value is a power of two as well. And of course you can easily detect which power of two it is.
how could you do this?
assume i have a 4 bit unsigned int, to make things easy. the bits are
ordered 1423. so decimal to binary:
1 == 1000
2 == 0010
3 == 1010
....
how can you detect that 1 is bit pattern 1000?
On 2006-03-31, tedu <tu@zeitbombe.o rg> wrote: Wojtek Lerch wrote: But of course you can detect the order, at least in cases where padding bits don't obscure the view. Take a look at the representation of a power of two. If there are no padding bits, only one of the bytes has a non-zero value, and that value is a power of two as well. And of course you can easily detect which power of two it is.
how could you do this?
assume i have a 4 bit unsigned int, to make things easy. the bits are ordered 1423. so decimal to binary: 1 == 1000 2 == 0010 3 == 1010 ...
how can you detect that 1 is bit pattern 1000?
How about a 16-bit unsigned int that shows up as
16 15 14 13 12 11 10 9 87651423
If you set it to 1, you could look at it as an array of two unsigned
chars and it shows up as 0x00 0x04
"tedu" <tu@zeitbombe.o rg> writes: Wojtek Lerch wrote: But of course you can detect the order, at least in cases where padding bits don't obscure the view. Take a look at the representation of a power of two. If there are no padding bits, only one of the bytes has a non-zero value, and that value is a power of two as well. And of course you can easily detect which power of two it is.
how could you do this?
assume i have a 4 bit unsigned int, to make things easy. the bits are ordered 1423. so decimal to binary: 1 == 1000 2 == 0010 3 == 1010 ...
how can you detect that 1 is bit pattern 1000?
You can detect the value of each bit (at run time, probably not at
compile time) by using an array of unsigned char to constructing N
values, each with exactly one bit set to 1 and all the others set to 0.
This works only if there are trap representations .
--
Keith Thompson (The_Other_Keit h) 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.
"David R Tribble" <da***@tribble. com> writes: Eric Sosman wrote: Or is the implementation free to scatter the bits of the "pure binary" representation among the different bytes as it pleases? (It must, of course, scatter the corresponding bits of signed and unsigned versions in the same way.)
Wojtek Lerch wrote: Of course.
True, but ISO C also encompasses existing practice. And existing practice throughout all of the history of mechanical computers has been to arrange the digits of machine words in some reasonably practical, if not completely obvious, way.
There is a limit to how far a language standard can go in covering all implementations , and that limit is usually dictated by actual existing implementations . ISO C does not cover trinary implementations (as far as I can tell) for the simple reason that it does not have to.
All of which makes it entirely reasonable and possible to invent a handful of standard macros that could adequately describe the salient characteristics of the underlying native hardware words used to implement the standard abstract datatypes of C.
[...]
There is precedent for introducing additional constraints on integer
representations . The C90 standard said very little about how integer
type are represented; C99 added a requirement that signed integers
must be either sign and magnitude, two's complement, or ones'
complement, and (after the standard was published) that all-bits-zero
must be a representation of 0.
If there are good reasons to do so, it might be reasonable to have
additional constraints in a new version of the standard, as long as no
existing or likely implementations violate the new assumptions. For
example, I doubt that any conforming C99 implementation would have a
PDP-11-style middle-endian representation (unless somebody's actually
done a C99 implementation for the PDP-11).
Figuring out what restrictions would be both reasonable and useful is
another matter.
--
Keith Thompson (The_Other_Keit h) 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.
"Jordan Abel" <ra*******@gmai l.com> wrote in message
news:sl******** *************** @random.yi.org. .. On 2006-03-31, tedu <tu@zeitbombe.o rg> wrote: Wojtek Lerch wrote: But of course you can detect the order, at least in cases where padding bits don't obscure the view. Take a look at the representation of a power of two. If there are no padding bits, only one of the bytes has a non-zero value, and that value is a power of two as well. And of course you can easily detect which power of two it is.
how could you do this?
assume i have a 4 bit unsigned int, to make things easy. the bits are ordered 1423. so decimal to binary: 1 == 1000 2 == 0010 3 == 1010 ...
how can you detect that 1 is bit pattern 1000?
How about a 16-bit unsigned int that shows up as 16 15 14 13 12 11 10 9 87651423
If you set it to 1, you could look at it as an array of two unsigned chars and it shows up as 0x00 0x04
Run this program on your implementation:
#include <stdio.h>
#include <limits.h>
typedef unsigned short TYPE;
int main( void ) {
union {
TYPE bit;
unsigned char bytes[ sizeof(TYPE) ];
} u;
unsigned i, j;
for ( u.bit = 1; u.bit != 0; u.bit <<= 1 )
for ( i=0; i<sizeof(TYPE) ; ++i )
for ( j=0; j<CHAR_BIT; ++j )
if ( u.bytes[i] & 1 << j )
printf( "%u\n", i * CHAR_BIT + j + 1 );
return 0;
}
If your machine has an N-bit unsigned short with no padding, the program
will print out a permutation of the numbers from 1 to N. The C standard
doesn't forbid any of the N! possible permutations, and the program allows
you to detect which one of them you're dealing with.
"Keith Thompson" <ks***@mib.or g> wrote in message
news:ln******** ****@nuthaus.mi b.org... This works only if there are trap representations .
If there are NO trap representations ?
Jordan Abel wrote: assume i have a 4 bit unsigned int, to make things easy. the bits are ordered 1423. so decimal to binary: 1 == 1000 2 == 0010 3 == 1010 ...
how can you detect that 1 is bit pattern 1000?
How about a 16-bit unsigned int that shows up as 16 15 14 13 12 11 10 9 87651423
If you set it to 1, you could look at it as an array of two unsigned chars and it shows up as 0x00 0x04
ah, thanks, i hadn't checked that unsigned char uses "pure binary
notation". but it would be 0x08, right? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Fao |
last post by:
Hi, I am in my first year of C++ in college and my professor wants me
to Write a Program with multiple functions,to input two sets of
user-defined data types:
One type named 'Sign' declared by "typedef" to contain only
either +10 or -10 and
the other type named Color declared by "enum" to contain only
black, blue, purple, red, white, and yellow.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |