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 happening so?
"printf function which will print in serial window"
No - printf will print to whatever the current implementation of putchar drives: http://www.keil.com/support/man/docs/c51/c51_printf.htm
printf itself is totally oblivious of where its output actually goes.
"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 behaviour...
Again, read the section in the Manual.
Or, are your talking about the NUL terminator that 'C' always uses for strings?
http://www.keil.com/support/docs/62.htm
http://www.keil.com/support/docs/99.htm
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".
Erik
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 integers.
There's an "enable ANSI integer promotion" checkbox somewhere if you want strict standards compliance at the expense of efficiency.
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 ?
"GENEROUS" indeed,
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.
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.
if there is no question of abuse, was there a need to mention it in the first place,
ab use???!
cool it, no abuse, no ditch, nothing, wat nonsense was that,
forum is cool as before,