Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

In these matters the only certainty is that there is nothing certain. -- Pliny the Elder


devel / comp.lang.c / Re: memset and data types

SubjectAuthor
* memset and data typesDFS
+* Re: memset and data typesJames Kuyper
|+- Re: memset and data typesKenny McCormack
|`* Re: memset and data typesKeith Thompson
| `- Re: memset and data typesJames Kuyper
+- Re: memset and data typesPeter 'Shaggy' Haywood
+- Re: memset and data typesbart
`- Re: memset and data typesKeith Thompson

1
memset and data types

<8u1BN.494091$83n7.388103@fx18.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33579&group=comp.lang.c#33579

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!nntp.comgw.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx18.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Betterbird (Windows)
Newsgroups: comp.lang.c
Content-Language: en-US
From: nos...@dfs.com (DFS)
Subject: memset and data types
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 6
Message-ID: <8u1BN.494091$83n7.388103@fx18.iad>
X-Complaints-To: abuse@blocknews.net
NNTP-Posting-Date: Tue, 20 Feb 2024 13:07:16 UTC
Organization: blocknews - www.blocknews.net
Date: Tue, 20 Feb 2024 08:07:26 -0500
X-Received-Bytes: 750
 by: DFS - Tue, 20 Feb 2024 13:07 UTC

void *memset(void *str, int c, size_t n)

I saw that memset accepts ints where n <= INT_MAX, but above that
requires n to be a size_t (or similar) variable.

Why does the function definition specify size_t?

Re: memset and data types

<ur2gtc$2ih6n$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33585&group=comp.lang.c#33585

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: memset and data types
Date: Tue, 20 Feb 2024 10:36:12 -0500
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <ur2gtc$2ih6n$1@dont-email.me>
References: <8u1BN.494091$83n7.388103@fx18.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 20 Feb 2024 15:36:12 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2311dfd12bdcb3d7a6ecb5135a8b8561";
logging-data="2704599"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/hikjPf4EuXjwfYg1cGCyGlqLuwaxbNUE="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:PjlABJoxxsDI1knWoUQFO+KsZ50=
In-Reply-To: <8u1BN.494091$83n7.388103@fx18.iad>
Content-Language: en-US
 by: James Kuyper - Tue, 20 Feb 2024 15:36 UTC

On 2/20/24 08:07, DFS wrote:
> void *memset(void *str, int c, size_t n)
>
> I saw that memset accepts ints where n <= INT_MAX, but above that
> requires n to be a size_t (or similar) variable.
>
> Why does the function definition specify size_t?

Because size_t is intended to be the type used for the size of objects.
A typical use would be memset(&obj, 0, sizeof obj), or memset(array, 0,
sizeof array). Many implementations allow objects with a size too large
to be represented by an int, while size_t is supposed to be (but is not
required to be) large enough to represent the size of any creatable object.

Re: memset and data types

<ur2oi2$1ijb6$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33592&group=comp.lang.c#33592

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!1.us.feeder.erje.net!feeder.erje.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.c
Subject: Re: memset and data types
Date: Tue, 20 Feb 2024 17:46:42 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <ur2oi2$1ijb6$1@news.xmission.com>
References: <8u1BN.494091$83n7.388103@fx18.iad> <ur2gtc$2ih6n$1@dont-email.me>
Injection-Date: Tue, 20 Feb 2024 17:46:42 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="1658214"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Tue, 20 Feb 2024 17:46 UTC

In article <ur2gtc$2ih6n$1@dont-email.me>,
James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
>On 2/20/24 08:07, DFS wrote:
>> void *memset(void *str, int c, size_t n)
>>
>> I saw that memset accepts ints where n <= INT_MAX, but above that
>> requires n to be a size_t (or similar) variable.
>>
>> Why does the function definition specify size_t?
>
>Because size_t is intended to be the type used for the size of objects.
>A typical use would be memset(&obj, 0, sizeof obj), or memset(array, 0,
>sizeof array). Many implementations allow objects with a size too large
>to be represented by an int, while size_t is supposed to be (but is not
>required to be) large enough to represent the size of any creatable object.
>

The real answer is that when there is a prototype in scope (as there will
be if you are doing things right), then when you pass an int as the 3rd
arg, it gets promoted to size_t in the call. I.e., the called function
always "sees" a size_t as the last argument (regardless of what you
actually passed in the call).

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/CLCtopics

Re: memset and data types

<87le7f3u1i.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33593&group=comp.lang.c#33593

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: memset and data types
Date: Tue, 20 Feb 2024 09:49:29 -0800
Organization: None to speak of
Lines: 22
Message-ID: <87le7f3u1i.fsf@nosuchdomain.example.com>
References: <8u1BN.494091$83n7.388103@fx18.iad> <ur2gtc$2ih6n$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="65843b3786512bc99ec54c23cf0b62cb";
logging-data="2755935"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+PhvEJlSU7E4207vY4pns1"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:2ILW41yNnZqHgs+PyYd4k93EfU0=
sha1:C9unmRvjU8AM14f/Ou6d5P4bFAU=
 by: Keith Thompson - Tue, 20 Feb 2024 17:49 UTC

James Kuyper <jameskuyper@alumni.caltech.edu> writes:
> On 2/20/24 08:07, DFS wrote:
>> void *memset(void *str, int c, size_t n)
>>
>> I saw that memset accepts ints where n <= INT_MAX, but above that
>> requires n to be a size_t (or similar) variable.
>>
>> Why does the function definition specify size_t?
>
> Because size_t is intended to be the type used for the size of objects.
> A typical use would be memset(&obj, 0, sizeof obj), or memset(array, 0,
> sizeof array). Many implementations allow objects with a size too large
> to be represented by an int, while size_t is supposed to be (but is not
> required to be) large enough to represent the size of any creatable object.

I believe C23 requires all objects to be no more than SIZE_MAX bytes.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Re: memset and data types

<ar9gak-ch1.ln1@hendrix.foo>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33643&group=comp.lang.c#33643

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: phayw...@alphalink.com.au (Peter 'Shaggy' Haywood)
Newsgroups: comp.lang.c
Subject: Re: memset and data types
Date: Wed, 21 Feb 2024 15:12:58 +1100
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <ar9gak-ch1.ln1@hendrix.foo>
References: <8u1BN.494091$83n7.388103@fx18.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7Bit
Injection-Info: dont-email.me; posting-host="cb3de182b3be218287d95cf165629bb1";
logging-data="3319185"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19VwGOz8ntqc9gegFDN55Qo5uZu+HVebXU="
User-Agent: KNode/0.10.9
Cancel-Lock: sha1:6xGDIt9EUAF/w+NWOYqOKoF5qcQ=
 by: Peter 'Shaggy&# - Wed, 21 Feb 2024 04:12 UTC

Groovy hepcat DFS was jivin' in comp.lang.c on Wed, 21 Feb 2024 12:07
am. It's a cool scene! Dig it.

> void *memset(void *str, int c, size_t n)
>
> I saw that memset accepts ints where n <= INT_MAX, but above that

Where did you see that? There is no such wording in the standard. From
N3096:

**********************************************************************
7.26.6.1 The memset function

Synopsis
1 #include <string.h>
void *memset(void *s, int c, size_t n);

Description
2 The memset function copies the value of c (converted to an unsigned
char) into each of the first n characters of the object pointed to by
s.

Returns
3 The memset function returns the value of s.
**********************************************************************

I don't think this has changed at all, save section numbering, since the
first version of the standard came out. (Has it, folks?)
And, as you can see, there's no stipulation that n <= INT_MAX. Is this
perhaps a limitation of the implementation you're using?

> requires n to be a size_t (or similar) variable.
> Why does the function definition specify size_t?

Are you kidding? It's the size parameter. Duh! What else would it be
but a size_t? That's what that type is for.
I sometimes use size_t for other things, because it just sort of fits
those uses. But the main purpose of size_t is to represent sizes.
D'ya have any more silly questions, hmm?

--

----- Dig the NEW and IMPROVED news sig!! -----

-------------- Shaggy was here! ---------------
Ain't I'm a dawg!!

Re: memset and data types

<ur4uam$35l9t$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33644&group=comp.lang.c#33644

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (bart)
Newsgroups: comp.lang.c
Subject: Re: memset and data types
Date: Wed, 21 Feb 2024 13:37:27 +0000
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <ur4uam$35l9t$1@dont-email.me>
References: <8u1BN.494091$83n7.388103@fx18.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 21 Feb 2024 13:37:26 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="5c79d5dc10139edba015f55b3649132d";
logging-data="3331389"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/iZ4fF6GTaAmSNEgJsf5Q0+LeqXsW6ZZc="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:WQM/UR6m3RLyTm0zH1PvODj3hss=
In-Reply-To: <8u1BN.494091$83n7.388103@fx18.iad>
Content-Language: en-GB
 by: bart - Wed, 21 Feb 2024 13:37 UTC

On 20/02/2024 13:07, DFS wrote:
> void *memset(void *str, int c, size_t n)
>
> I saw that memset accepts ints where n <= INT_MAX,

Where did you see that?

> but above that
> requires n to be a size_t (or similar) variable.
>
> Why does the function definition specify size_t?

On a 64-bit machine, you need to be able to work on memory blocks which
are bigger than 2GB, which is the limit if n had an int type.

On 32-bit and smaller, then size_t will probably be limited to 32 or 16
bits. But `int` would still be insufficient, as it needs to be unsigned
to allow counts above 0x7FFFFFFF or above 0x7FFF.

Re: memset and data types

<87cysp4y93.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33645&group=comp.lang.c#33645

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: memset and data types
Date: Wed, 21 Feb 2024 07:45:28 -0800
Organization: None to speak of
Lines: 25
Message-ID: <87cysp4y93.fsf@nosuchdomain.example.com>
References: <8u1BN.494091$83n7.388103@fx18.iad>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="fd7275f81d64c11c415d0701c07f5ab4";
logging-data="3400299"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19QbAVJ6k5d5Ar5+7v5MNOz"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:l1A2/XQr7PclGcfEohbQWGJIoAU=
sha1:9if+YcQZBqGBBJlROJ8BC/cG2bM=
 by: Keith Thompson - Wed, 21 Feb 2024 15:45 UTC

DFS <nospam@dfs.com> writes:
> void *memset(void *str, int c, size_t n)
>
> I saw that memset accepts ints where n <= INT_MAX, but above that
> requires n to be a size_t (or similar) variable.

That's strictly true, but it's an odd way to say it.

You can certainly pass an int value as the third argument to memset(),
and of course any int value must be <= INT_MAX. It will be implicitly
converted from int to size_t. (It's conceivable, but implausible, that
INT_MAX could be greater than SIZE_MAX.)

The argument can be of any arithmetic type, and it will be converted to
size_t, but it usually makes sense for the argument to be of the
parameter type. There's nothing special about int in this context.

> Why does the function definition specify size_t?

Because it's a size.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Re: memset and data types

<ur57qm$38b6b$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33646&group=comp.lang.c#33646

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.neodome.net!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: memset and data types
Date: Wed, 21 Feb 2024 11:19:34 -0500
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <ur57qm$38b6b$1@dont-email.me>
References: <8u1BN.494091$83n7.388103@fx18.iad> <ur2gtc$2ih6n$1@dont-email.me>
<87le7f3u1i.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 21 Feb 2024 16:19:38 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="f679441fdf6cd96c59400d664f91e949";
logging-data="3419339"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19G1mnFVVA0FAFuWfghha9W19ujjnX1m1U="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:YZyTvuGzJLQYtHsQY1/0wXjJI8w=
Content-Language: en-US
In-Reply-To: <87le7f3u1i.fsf@nosuchdomain.example.com>
 by: James Kuyper - Wed, 21 Feb 2024 16:19 UTC

On 2/20/24 12:49, Keith Thompson wrote:
> James Kuyper <jameskuyper@alumni.caltech.edu> writes:
....
>> Because size_t is intended to be the type used for the size of objects.
>> A typical use would be memset(&obj, 0, sizeof obj), or memset(array, 0,
>> sizeof array). Many implementations allow objects with a size too large
>> to be represented by an int, while size_t is supposed to be (but is not
>> required to be) large enough to represent the size of any creatable object.
>
> I believe C23 requires all objects to be no more than SIZE_MAX bytes.

True: "A complete type shall have a size that is less than or equal to
SIZE_MAX." (6.2.5p28)

Sorry - I haven't had time to absorb all of the changes made in c2023 yet.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor