Searching \ for 'memset' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=memset
Search entire site for: 'memset'.

Truncated match.
PICList Thread
'memset'
2000\02\02@134001 by Peter Keller

flavicon
face
Question:
Which one of the following is correct, a or b ?

long val[8];  // long = 16 bits
memset(val,0x05,sizeof(val));

a)  val[0] : 0x0505
    .....
   val[7] : 0x0505

b) val[0] : 0x0005
   .....
   val[7] : 0x0005

Peter

2000\02\02@135004 by John Pfaff

flavicon
face
That memset will give you val[0] through val[3] = 0x0505 and val[4] through
val[7] = 0x0000;

the right way to do it is (assuming you want 0x0505 and not 0x0005)
memset( val, 0x05, 8 * sizeof( long ));

----- Original Message -----
From: Peter Keller <spam_OUTpkellerTakeThisOuTspamDATALINK.CH>
To: <.....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU>
Sent: Wednesday, February 02, 2000 1:39 pm
Subject: memset


Question:
Which one of the following is correct, a or b ?

long val[8];  // long = 16 bits
memset(val,0x05,sizeof(val));

a)  val[0] : 0x0505
    .....
   val[7] : 0x0505

b) val[0] : 0x0005
   .....
   val[7] : 0x0005

Peter

2000\02\02@135835 by John Pfaff

flavicon
face
I forgot to mention that if you want 0x0005, you can either write a version
of memset (perhaps lmemset) that assigns longs, or do each assignment
individually.

{Original Message removed}

2000\02\02@140045 by Peter Keller

flavicon
face
John Pfaff schrieb:

> That memset will give you val[0] through val[3] = 0x0505 and val[4] through
> val[7] = 0x0000;

You're right, but CCS does it as version a) !

{Quote hidden}

2000\02\02@150248 by William Chops Westfield

face picon face
   long val[8];  // long = 16 bits
   memset(val,0x05,sizeof(val));

   a)  val[0] : 0x0505
        .....
       val[7] : 0x0505

That's the correct one.  Here's quote from a unix man page:

SunOS 5.5.1         Last change: 22 Jan 1993                    1

memory(3C)             C Library Functions             memory(3C)

    memset() sets the first n bytes in  memory  area  s  to  the
    value of c (converted to an unsigned char).  It returns s.


BillW

2000\02\03@010452 by Peter Keller

flavicon
face
William Chops Westfield schrieb:

>     long val[8];  // long = 16 bits
>     memset(val,0x05,sizeof(val));
>
>     a)  val[0] : 0x0505
>          .....
>         val[7] : 0x0505
>
> That's the correct one.  Here's quote from a unix man page:
>
> SunOS 5.5.1         Last change: 22 Jan 1993                    1
>
> memory(3C)             C Library Functions             memory(3C)
>
>      memset() sets the first n bytes in  memory  area  s  to  the
>      value of c (converted to an unsigned char).  It returns s.
>

That's what K&R says:
Except ... the first n characters ... which is not as clear as bytes !

>
> BillW

2000\02\03@033955 by Andy Baker

flavicon
face
Actually, (a) is completely correct, although the alternative below will
also work just fine, and avoids any potential confusion.

K&R defines that sizeof(val) will return the number of bytes in the array
val, not just the size of the pointer to the array, so sizeof(val) returns
16 as required.

This is why CCS got it right.

It's these subtle bits about C that cause many bugs!

Cheers,

Andy

{Original Message removed}

2000\02\03@052008 by Peter Keller

flavicon
face
Andy Baker schrieb:

> Actually, (a) is completely correct, although the alternative below will
> also work just fine, and avoids any potential confusion.
>
> K&R defines that sizeof(val) will return the number of bytes in the array
> val, not just the size of the pointer to the array, so sizeof(val) returns
> 16 as required.
>
> This is why CCS got it right.
>
> It's these subtle bits about C that cause many bugs!

no, only one bug - the next one !

>
>
> Cheers,
>
> Andy
>
> {Original Message removed}

More... (looser matching)
- Last day of these posts
- In 2000 , 2001 only
- Today
- New search...