Re: Doubt in memcpy() and memset()



Tom St Denis wrote:

Kenneth Brody wrote:
No, but if you are passing an int rather than unsigned char, it
may need to zero-fill the rest of the int before passing it.

unsigned char x;
int ix;

x = 4;
ix = x;

What am I missing?

totally legal conversion provided you keep the values in x to the
portable range.

I may be mistaken here, but...

extern void foo(unsigned char c);
extern void bar(int i);

void foobar()
{
unsigned char c = 'x';

foo(c);
bar(c);
}

Here, the call to foo() can push the single byte of c (if the system
allows one to push a byte), or load the byte into a register and then
push the register. However, the call to bar() requires that the byte
be loaded into a register, while zero-filling the register prior to
pushing it on the stack.

Perhaps something like:

load al,[c]
push eax
call foo

xor eax,eax
load al,[c]
push eax
call bar

(Yes, this example assumes the concept of registers and a stack.)

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:ThisIsASpamTrap@xxxxxxxxx>


.



Relevant Pages

  • Re: Pascal-like set class
    ... one reason would be a memory-mapped register accessed across a VME ... If I had a large set, then sure, I would use int, because the set operations ... (maybe its in a struct talking to an Ada record, ... by setting the unit type to unsigned char. ...
    (comp.lang.cpp)
  • Re: Doubt in memcpy() and memset()
    ... Most platforms won't let you push a char on the stack ... No, but if you are passing an int rather than unsigned char, it ...
    (comp.lang.c)
  • [PATCH,RFC 2.6.14 13/15] KGDB: CFI annotations for better unwinding
    ... * Note that this register image is in a different order than ... unsigned char li_min_insn_length; ... +/* Tag names and codes. ... +enum dwarf_form ...
    (Linux-Kernel)
  • [patch 12/15] KGDB: Add CFI DWARF2 annotation support.
    ... * Note that this register image is in a different order than ... unsigned char li_min_insn_length; ... +/* Tag names and codes. ... +enum dwarf_form ...
    (Linux-Kernel)
  • [patch 13/16] Add CFI DWARF2 annotation support
    ... * Note that this register image is in a different order than ... unsigned char li_min_insn_length; ... +/* Tag names and codes. ... +enum dwarf_form ...
    (Linux-Kernel)