Sujet : Re: Regarding assignment to struct
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 05. May 2025, 22:10:07
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20250505135415.417@kylheku.com>
References : 1 2 3 4 5 6 7
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2025-05-05, Keith Thompson <Keith.S.Thompson+
u@gmail.com> wrote:
Michael S <already5chosen@yahoo.com> writes:
On Mon, 05 May 2025 01:34:16 -0700
Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
And more obviously, "%p" requires an argument of type void*, not int*.
>
That part of otherwise very good comment is unreasonably pedantic.
>
I disagree. I suggest it's a bad habit to use "%p" without ensuring,
by a cast if necessary, that the argument is of type void*.
>
In most implementations, it's likely that all pointers have the same
size and representation and are passed as arguments in the same way,
but getting the types right means one less thing to worry about.
If the codebade assumes all data pointers are the same size, bit pattern
and are treated the same in the calling conventions / ABI, then it
is probably moot.
That code is doomed on a platform where the assumption doesn't hold, and
the printf statemnts are probably not independently reusable.
(I mostly put in these casts just to communicate to others that
an ISO C language lawyer works here, if you happen to need one.)
Also, it owuld be amazingly stupid of any such platform not just
make those printfs work: to promote variadic arguments of
pointer-to-object type to a common representation which is the same as
void *, combined with a matching behavior in the va_arg macro for
extracting the value back into any pointer-to-object type.
Mountains of non-standard-conforming code exert tremendous pressure on
both hardware platforms and the way C implementations are adapted to
those platforms.
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca