NetBSD-Docs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: strcpy(3) examples use of sizeof



On Sat, Dec 10, 2022 at 21:18:00 -0500, Jan Schaumann wrote:

> Valery Ushakov <uwe%stderr.spb.ru@localhost> wrote:
> > On Sat, Dec 10, 2022 at 17:24:24 -0500, Jan Schaumann wrote:
> > 
> > > How do you feel about adding a separate manual page for the sizeof
> > > operator?
> > 
> > I don't think it's a good idea.
> 
> The reason I think it would be useful is that I see
> novice programmers frequently make mistakes.  Their
> general go-to solution rather than manual pages is
> Google and Stack Overflow, and there they tend to pick
> up wrong use cases or unbaked solutions.

A man page is not very useful for someone who by your own admission is
not going to read it or even look for it to begin with anyway, is it? :)


> For 'sizeof', there is no good reference (other than the C standard,
> I suppose) that allows them to easily look up what it does or how to
> use it.

To be pedantic, the sizeof() itself is mostly trivial, it's the
platform struct layout ABI, alignment requirements, etc that affect
object size that are interesting.  The sizeof just reports the end
result. Note how in the proposed text you end up mostly discussing
those aspects, not the trivial sizeof itself.

But my impression (especially given the previous history of this
thread) is that the whole man page is written as padding for the
sentence:

  It is a common mistake to apply sizeof to a dynamically allocated
  array:

which, ironically, doesn't have _anything_ to do with the preceding
discussion of the ABI layout.

Now, a psABI summary in a man page format - that would be very nice
indeed!


> Having a manual page would, I think, help people.

To use an analogy, the proposed text is kinda like starting a
strlen(3) man page with a long discussion of how zero-terminated
strings are used in C.  If will not help too much a newbie and it will
be usless noise for someone who knows how C strings work.


> > A man page is not the right medium/format for this.
> 
> What would be the right format or medium?

A proper book on C programming? :)

I don't know.  The issue is not that this particular man page is
missing.  The issue is that the whole information consumption style is
different now.  But that is too huge a digression (I deleted what I
had written when I realized that I was using the comparision of Fux'es
"Gradus ad Parnassum" and its English translation as an argument).


> I mean, we ship e.g., cdefs(3), types(3), offsetof(3),
> and c(7), which strike me as similar.

None of them are language features.  offsetof(3) is indeed in the
standard, but so is strlen(3).


-uwe


Home | Main Index | Thread Index | Old Index