Using char

P

pete

Dan said:
Where does the standard say that?

The standard doesn't actually refer to
an unsigned short variable named "a".

N869
7.19.6.1 The fprintf function
[#6]
h Specifies that a following d, i, o, u, x, or X
conversion specifier applies to a short int or
unsigned short int argument (the argument will
have been promoted according to the integer
promotions, but its value shall be converted to
short int or unsigned short int before
printing); or that a following n conversion
specifier applies to a pointer to a short int
argument.
 
D

Dan Pop

In said:
The standard doesn't actually refer to
an unsigned short variable named "a".

If you read the standard carefully, you'll see that all conversion
descriptors require a well specified argument type and it's not clear
at all that %h[ouxX] is an exception.

Dan
 
J

Johnny

a = 321;
Are you sure? Unless it is UB (of which I'm not sure), it should output
a = 65

Please forgive my stupidity. But what does UB stand for and mean?

Thanks
 
R

Richard Heathfield

Johnny said:
[...] what does UB stand for and mean?

UB means "undefined behaviour", and refers to code whose result is not laid
down by the C standard. Examples include void main, fflush(stdin),
gets(NULL), and a trillion other examples of bad programming.
 
M

Minti

Johnny said:
Please forgive my stupidity. But what does UB stand for and mean?


UB -- > Undefined Behaviour


Here is an exact definition

http://dspace.dial.pipex.com/town/green/gfd34/art/welcome.html

Or on a light note here is a definition from standard
<quote>

undefined behavior
behavior, upon use of a nonportable or erroneous program construct, of
erroneous data, or of indeterminately valued objects, for which this
International Standard imposes no requirements
2 NOTE Possible undefined behavior ranges from ignoring the situation
completely with unpredictable
results, to behaving during translation or program execution in a
documented manner characteristic of the
environment (with or without the issuance of a diagnostic message), to
terminating a translation or
execution (with the issuance of a diagnostic message).



3 EXAMPLE An example of undefined behavior is the behavior on integer
overflow.



</quote>
 
M

Malcolm

Johnny said:
Please forgive my stupidity. But what does UB stand for and mean?
UB is "undefined behaviour", like writing to an uninitialised pointer.

The point is that UB means a program is always incorrect. It may produce
correct output, or what the programmer "means", but it is not correct as a C
program.

It shouldn't be confused with implementation-defined behaviour, which is
correct but not portable.
 
D

Dan Pop

In said:
Johnny said:
[...] what does UB stand for and mean?

UB means "undefined behaviour",

How do you know? What is preventing UB from meaning "unspecified
behaviour", which, in the context of the C standard, is a completely
different beast?

Because of this ambiguity, UB should be avoided, unless the context
provides enough information for disambiguation.

Dan
 
M

Minti

Richard Heathfield said:
Johnny said:
[...] what does UB stand for and mean?

UB means "undefined behaviour", and refers to code whose result is not laid
down by the C standard. Examples include void main, fflush(stdin),
gets(NULL), and a trillion other examples of bad programming.



Just a curious, irrelevant question, if there are trillion examples of
bad programming, how many examples are there of good programming.
Certainly not a trillion.
 
R

Richard Heathfield

Minti said:
Richard Heathfield said:
Johnny said:
[...] what does UB stand for and mean?

UB means "undefined behaviour", and refers to code whose result is not
laid down by the C standard. Examples include void main, fflush(stdin),
gets(NULL), and a trillion other examples of bad programming.



Just a curious, irrelevant question, if there are trillion examples of
bad programming, how many examples are there of good programming.
Certainly not a trillion.


It's trivial to write code to generate a trillion examples of good
programming.

Might take up a fair bit of storage, though.
 
R

Richard Heathfield

Dan said:
In <bo0m6p$crp$1@titan.btinternet.com> Richard Heathfield
Johnny said:
[...] what does UB stand for and mean?

UB means "undefined behaviour",

How do you know? What is preventing UB from meaning "unspecified
behaviour", which, in the context of the C standard, is a completely
different beast?

Nothing, which is why I suggested the alternatives UDB and USB, some time
ago. In message <3DC78EAC.360E5936@eton.powernet.co.uk> I said: "Others in
this newsgroup call undefined behaviour "UB", but there is nothing to
disambiguate that from "unspecified behaviour", so I think it a poor
abbreviation. UDB and USB, *within the context of this newsgroup*, are not
ambiguous."
Because of this ambiguity, UB should be avoided, unless the context
provides enough information for disambiguation.

UB should /always/ be avoided.
 
D

Dan Pop

In said:
Dan said:
In <bo0m6p$crp$1@titan.btinternet.com> Richard Heathfield
Johnny wrote:

[...] what does UB stand for and mean?

UB means "undefined behaviour",

How do you know? What is preventing UB from meaning "unspecified
behaviour", which, in the context of the C standard, is a completely
different beast?

Nothing, which is why I suggested the alternatives UDB and USB, some time
ago.

Bad idea, since USB already has a well defined meaning and because we
can't realistically expect people who have just joined the newsgroup
(regardless of their experience as C programmers) to be able to figure
out the meaning of such abbreviations.
In message <3DC78EAC.360E5936@eton.powernet.co.uk> I said: "Others in
this newsgroup call undefined behaviour "UB", but there is nothing to
disambiguate that from "unspecified behaviour", so I think it a poor
abbreviation. UDB and USB, *within the context of this newsgroup*, are not
ambiguous."

Imagine that right after you joined c.l.c you saw UDBs and USBs all over
the place. Would you have been able to figure out their meaning?

Even if one doesn't fully understand the meanings of "unspecified
behaviour" and "undefined behaviour" (and, especially, the difference
between them), at least one can figure out what the poster is talking
about.

So, if we don't want to turn c.l.c into a closed club for the regulars,
there is no place for such abbreviations here.
UB should /always/ be avoided.

OK, I'll bite: how do you avoid the unspecified behaviour in

printf("Hello world\n");

?

Dan
 
M

Minti

Richard Heathfield said:
Minti said:
Richard Heathfield said:
Johnny wrote:

[...] what does UB stand for and mean?

UB means "undefined behaviour", and refers to code whose result is not
laid down by the C standard. Examples include void main, fflush(stdin),
gets(NULL), and a trillion other examples of bad programming.



Just a curious, irrelevant question, if there are trillion examples of
bad programming, how many examples are there of good programming.
Certainly not a trillion.


It's trivial to write code to generate a trillion examples of good
programming.

Might take up a fair bit of storage, though.


Maybe it could scan all the USENET c.l.c and get a trillion examples
of good programming.


Might have to filter out fair bit of bad programs though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,302
Messages
2,571,547
Members
48,349
Latest member
JolieEey92
Top