Does the c standard state that for all c99 implementation char as standard
is equal unsigned char ??? - or do i have to take this into account when
writing my program ???. 10 14423
Lars Tackmann wrote: Does the c standard state that for all c99 implementation char as standard is equal unsigned char ?
Not at all. It's equivalent to either signed char or unsigned char.
The choice is up to the implementation.
It's not _equal_ to either, though. It's a distinct type, so
char *foo;
unsigned char *bar = foo;
is an error even if char is equivalent to unsigned char.
--
Hallvard
Lars Tackmann <ro****@diku.dk > wrote: Does the c standard state that for all c99 implementation char as standard is equal unsigned char ??? - or do i have to take this into account when writing my program ???.
The implementation has to pick one from {signed|unsigne d} char
for "plain" char:
ISO/IEC 9899:1999 6.2.5#15
The three types char, signed char, and unsigned char are
collectively called the character types. The implementation
shall define char to have the same range, representation,
and behavior as either signed char or unsigned char.
and
ISO/IEC 9899:1999 6.3.1.1#3
The integer promotions preserve value including sign. As
discussed earlier, whether a "plain" char is treated as
signed is implementation-defined.
HTH
Regards
--
Irrwahn Grausewitz (ir*******@free net.de)
welcome to clc : http://www.angelfire.com/ms3/bchambl...me_to_clc.html
clc faq-list : http://www.eskimo.com/~scs/C-faq/top.html
acllc-c++ faq : http://www.contrib.andrew.cmu.edu/~a...acllc-c++.html
Hallvard B Furuseth wrote: Lars Tackmann wrote:
Does the c standard state that for all c99 implementation char as standard is equal unsigned char ?
Not at all. It's equivalent to either signed char or unsigned char. The choice is up to the implementation.
It's not _equal_ to either, though. It's a distinct type, so char *foo; unsigned char *bar = foo; is an error even if char is equivalent to unsigned char.
Note that pointers to unsigned char can point to any byte in an object.
So if foo had been properly initialised the above would have been legal.
But even
int *p;
int *p2 = p;
is an error since it uses the value of an uninitialised variable.
--
Thomas.
Thomas Stegen <ts*****@cis.st rath.ac.uk> spoke thus: int *p; int *p2 = p;
Is ( p==NULL ) likewise undefined?
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Christopher Benson-Manica wrote: Thomas Stegen <ts*****@cis.st rath.ac.uk> spoke thus:
int *p; int *p2 = p;
Is ( p==NULL ) likewise undefined?
Yes. No expression that uses the value of an uninitialized pointer
variable has defined behaviour.
Jeremy.
Jeremy Yallop <je****@jdyallo p.freeserve.co. uk> spoke thus: Yes. No expression that uses the value of an uninitialized pointer variable has defined behaviour.
Does that hold true for non-pointer variables as well? Such as
int i;
if( i != 42 ) {
printf( "What a tragedy...\n" );
}
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Christopher Benson-Manica wrote: Jeremy Yallop <je****@jdyallo p.freeserve.co. uk> spoke thus:
Yes. No expression that uses the value of an uninitialized pointer variable has defined behaviour. Does that hold true for non-pointer variables as well?
Not in every case. Since the bit pattern of an uninitialized object
is indeterminate, whether the behaviour is defined depends on whether
all
It does, but the particular type of behaviour - undefined,
unspecified, etc. - depends on the type of the variable and possibly
on the implementation. For example, all bit patterns have valid
unsigned char values, so using an uninitialized unsigned char object
in an arithmetic expression never invokes undefined behaviour. Some
such expressions may even have well-defined behaviour; the following
assertion cannot fail.
unsigned char c;
assert(!(c - c));
Such as
int i; if( i != 42 ) { printf( "What a tragedy...\n" ); }
It's unspecified whether or not this code has undefined behaviour. On
an implementation where all possible bit patterns represent valid int
values the behaviour is not undefined, because the standard imposes
requirements on it: `i' has either the value 42 or some other valid
value. On an implementation with trap values for int, the code has
undefined behaviour.
Jeremy.
Jeremy Yallop <je****@jdyallo p.freeserve.co. uk> spoke thus: Not in every case. Since the bit pattern of an uninitialized object is indeterminate, whether the behaviour is defined depends on whether all
Lose your train of thought? Did Agent Smith pay you an unwelcome
visit? ;)
It does, but the particular type of behaviour (etc.)
Glad to see Agent Smith let you live this time. Seriously, thanks.
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Thomas Stegen wrote: Hallvard B Furuseth wrote:
char *foo; unsigned char *bar = foo; is an error even if char is equivalent to unsigned char. Note that pointers to unsigned char can point to any byte in an object. So if foo had been properly initialised the above would have been legal.
No, assignment between different pointer types are not legal.
OTOH, using a cast is OK: unsigned char *bar = (unsigned char*) foo;
But even int *p; int *p2 = p;
is an error since it uses the value of an uninitialised variable.
Oops. I should have said 'char *foo = "something" ;'.
--
Hallvard This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: MiniDisc_2k2 |
last post by:
Okay, here's a question about the standard. What does it say about
unsigned/signed mismatches in a comparison statement:
char a = 3;
unsigned char b = 255;
if (a<b)
Now what's the real answer here? If a is converted to unsigned, then b>a.
But, if b is converted to signed,then a>b. What's the correct coversion
(what is the compiler supposed to do?)
|
by: Siemel Naran |
last post by:
Hi. Is there a way to convert the type signed int to the type unsigned int,
char to unsigned char, signed char to unsigned char, and so on for all the
fundamental integer types? Something like
template <>
struct to_unsigned<signed int> : public std::unary_function<signed int,
unsigned int>
{
unsigned int operator()(signed int x) const { return x; }
};
|
by: tinesan |
last post by:
Hello fellow C programmers,
I'm just learning to program with C, and I'm wondering what the
difference between signed and unsigned char is. To me there seems to
be no difference, and the standard doesn't even care what a normal char
is (because signed and unsigned have equal behavior).
For example if someone does this:
unsigned char a = -2; /* or = 254 */
|
by: ravinderthakur |
last post by:
hi all experts,
can anybody explain me the difference between the
unsigned char and char in c/c++ langugage.
specifically how does this affects the c library fucntion such as
strcat,strtok etc and
their implementation.the way compiler treats them and the scenarios
where one
|
by: QQ |
last post by:
Hello,
Here is my simple program
int main()
{
unsigned char a =0x81;
char b = 0x81;
printf("unsigned char = 0x%x(%d), char = 0x%x(%d)\n",a,a,b,b);
printf("cast char to unsigned 0x%x\n",(unsigned char)b);
}
| |
by: Stephen Cawood |
last post by:
I'm trying to use a C++ .lib from C# (I tried the Interop group will no
results).
I have a working wrapper DLL (I can get back simple things like int), but
I'm having issues dealing with an array of bytes.
For example, the .lib contains this function:
int create(int id, int scale, unsigned char *image);
In the wrapper DLL I have this function:
|
by: ryanlee101 |
last post by:
I am getting a exception error when I complie my code.
The error is:
- imageData 0x00000000 <Bad Ptr>
type unsigned char *
I think it is from when I declare some of my char variables
|
by: =?gb2312?B?wNbA1rTzzOzKpg==?= |
last post by:
i wrote:
-----------------------------------------------------------------------
----------------------------------------
unsigned char * p = reinterpret_cast<unsigned char *>("abcdg");
sizeof(reinterpret_cast<const char *>(p));
-----------------------------------------------------------------------
----------------------------------------
the compiler tells me that "reinterpret_cast from type "const char * "
to type "unsigned char *"...
|
by: Steven |
last post by:
Hello, everyone!
I find a version of strcpy(), I don't know why it return the unsigned
char value.
Can I change it into return *s1-*s2?
int strcmp(const char *s1, const char *s2)
{
while (*s1 == *s2)
{
|
by: Kenzogio |
last post by:
Hi,
I have a struct "allmsg" and him member :
unsigned char card_number; //16
allmsg.card_number
|
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: 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: 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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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: 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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |