I am writing some serial data transfer apllication, i was seeing
some examples given by keil. in that hello world example i have seen.
i that they have used printf function which will print in serial
window.... there if i am using printf("%x",variable say 'a');there it
is appeding a zero at the end of variable. please clarify y it is
It does not happen,
how will it print without a '0' put in there,
"printf function which will print in serial window"
No - printf will print to whatever the current
implementation of putchar drives:
printf itself is totally oblivious of where its output
"it is appeding a zero at the end of variable."
What do you mean by that?
Remember that %x assumes an int, which is 16 bits in C51 -
if you pass it something smaller than 16 bits, you will get undefined
Again, read the section in the Manual.
Or, are your talking about the NUL terminator that 'C' always uses
"It does not happen"
How can you possibly say that? You haven't seen his code - there
could very possibly be something in there that causes it!
Andy, Andy, you do not get it. Reading is not cool.
Suggesting that the young folks should read, let alone learn to
code like we dinosaurs did instead of posting "plz send me the code"
is ridiculous. Why should they even think of doing any actual work
when some generous dinosaur will respond to "plz send me the code". I
do wonder however what they will do when we dinosaurs go gently into
the good night and no one will respond to "plz send me the code".
ANSI C specifies that values passed as parameters are promoted to
"integers" if they are smaller. In Keil C, an int is 16 bits. Passing
bytes as integers creates significant overhead on a 8-bit processor.
So, by default, Keil does not pass byte-sized arguments as
There's an "enable ANSI integer promotion" checkbox somewhere if
you want strict standards compliance at the expense of
Variable argument functions like printf() have a problem: how do
they know the width of the passed arguments? For printf(), the format
string provides the answer. Standard C has the %lx and %x formats.
Note that you have to explicitly tell printf() that it's a "long
integer" and not an "integer", because they might be different sizes.
Keil extends this notion with a 'b' prefix for single-byte integers.
You need to use "%bx", "%bu", etc., for the arguments you pass as a
byte. Otherwise, printf can't find the correct arguments.
If the format string and actual argument sizes do not match,
printf will generally output garbage from the variable-argument
buffer, which often enough will happen to be zero.
The forum goes on coz of such 'generous' people,
of course, you do learn by responding to such queries,
and often stops because the generosity is abused.
Erik, thats what you think,
what will happen to forum if everybody thinks so,
both the parties fear if its so, or not,
"and often stops because the generosity is abused."
because of abuse or fear of getting abused ?
nope, because of unwillingness ... naah being to lazy to answer
questions, probably not having any self written code.
NOBODY, willing to do some work thenseleves get 'abused'. Those
that that post "shut up and give me the code' deserve to be told that
there is a difference between 'programming' and 'copying' and if that
is 'abuse', so be it.
have you checked that how can u tell so
what is to be checked?
Yes some folks like to abuse. Check out this bit of abuse given
out by one of our own. " comment is like somenone standing in an
elevator and claiming the building is going up and down.
View all questions in Keil forum