|
From: Per W. <pw...@ia...> - 2003-03-04 22:25:20
|
short s = 'ab';
int i = 'abcd';
given that int is 4 byte.
But a lot of compilers will give you warnings, since it you can't be sure
if memcpy(buf,&s,sizeof(s)) will give you
buf[0] = 'a', buf[1] = 'b';
or
buf[0] = 'b', buf[1] = 'a';
In short - be very careful about using this feature. One place where it's
elegant to use is if you are reading a tagged file, where each tag is
4-byte long:
char *buf;
int tag = 0;
for (i = 0; i < 4; i++) {
tag = (tag << 8) | *buf++;
}
switch (tag) {
case 'STRT': ...; break;
case 'HEDR': ...; break;
case 'DATA': ...; break;
case 'ENDF': ...; break;
}
If there are a lot of tags, the result is a very fast matching of the
tags.
/Per W
On Tue, 4 Mar 2003, Giligun wrote:
> How does one get a char variable to hold more than one
> character? Or what other type should be used?
>
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
> http://mailplus.yahoo.com
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Etnus, makers of TotalView, The debugger
> for complex code. Debugging C/C++ programs can leave you feeling lost and
> disoriented. TotalView can help you find your way. Available on major UNIX
> and Linux platforms. Try it free. www.etnus.com
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|