|
|
Subscribe / Log in / New account

What's in a (type) name?

What's in a (type) name?

Posted Sep 3, 2022 3:07 UTC (Sat) by ABCD (subscriber, #53650)
In reply to: What's in a (type) name? by abatters
Parent article: What's in a (type) name?

The portable (as of C99) way to use printf and scanf (in userspace) with those types is to do things like:

#include <inttypes.h>

uint64_t x = 777;

printf("%" PRIu64, x);
scanf("%" SCNu64, &x);


to post comments

What's in a (type) name?

Posted Sep 3, 2022 16:37 UTC (Sat) by pm215 (subscriber, #98099) [Link] (5 responses)

Yes, but the compiler often won't warn if you forget and instead use the format specifier for the underlying type by mistake. Also the portable way is more longwinded and annoyingly requires you to close and reopen the string, which breaks the design principle that the right thing should be the easy thing :-(

What's in a (type) name?

Posted Sep 3, 2022 19:55 UTC (Sat) by SAI_Peregrinus (subscriber, #151778) [Link] (2 responses)

> breaks the design principle that the right thing should be the easy thing :-(

When has that ever been a design principle of C?

What's in a (type) name?

Posted Sep 4, 2022 12:01 UTC (Sun) by jezuch (subscriber, #52988) [Link]

That depends on what "the right thing" is. In C, designed for systems programing in the 70s, when things were different, that would be "easily map to hardware". (Differently on each hardware architecture, of course, but the exact details are, well, undefined! So it's not clear it succeeds even at that.)

What's in a (type) name?

Posted Sep 5, 2022 11:06 UTC (Mon) by pm215 (subscriber, #98099) [Link]

I meant it in the sense of a general principle of good API design. (It's one of the ideas of Rusty Russell's set of levels of API design: https://ozlabs.org/~rusty/index.cgi/tech/2008-03-30.html ) C of course has many parts which are not well-designed (for various reasons including 'historical'), and this is one of them.

What's in a (type) name?

Posted Sep 5, 2022 23:51 UTC (Mon) by skissane (subscriber, #38675) [Link] (1 responses)

> Also the portable way is more longwinded and annoyingly requires you to close and reopen the string

Really, the C standards committee should introduce a nicer way of doing that.

%(u64) or something like that. (I don't know which punctuation symbols are in use or reserved and which are not, but surely someone can come up with something which doesn't clash with existing uses.)

What's in a (type) name?

Posted Sep 6, 2022 23:02 UTC (Tue) by dezgeg (subscriber, #92243) [Link]


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds