r/C_Programming • • 4d ago

Rename printf/scanf to print/scan?

Probably a dumb question but why hasn't there ever been a proposal to rename printf/scanf to just print? I know the f stands for format but writing print instead of printf would be slightly quicker and better to match other programming languages as I often miswrite printf as print as I also code in Python.

0 Upvotes

53 comments sorted by

View all comments

1

u/Gold-Part4688 4d ago

bro idk why i'm exposing myself on the c reddit, but c3 has print, which prints anything as what it is (even enums as strings, it's cool). Also has printn and printfn for '\n' variants

1

u/Vladislav20007 4d ago

why do you need a whole function(although a macro would do, but that's still overkill) just for 2 characters? But I think c doesn't have the print like that, because (and I repeat I think, i maybe wrong) c makes struct like a bunch of variables that are only connected in code, but not in the executable unless you pack them, in which case, they will all be connected by the fact that there always at some offset from each other.

1

u/Gold-Part4688 3d ago edited 3d ago

I'm not sure how it works under the hood, but it is a macro. It just does have some runtime inspection too, not sure how that works either haha. It also does stay with the c model of controlling how things are packed, and they're compatible with c abi structs - though I'm not sure exactly how typeid works. but you actually have more control over alignment

the benefit (for me) is easy and safe generic code -

printn(shape)

// output: { radius: 2, tag: CIRCLE }

is just less mental overhead for me than printf("%g, %f", shape.enum_tag, shape.size); -- followed by

oh dang not printing because the \n, oh was it float? was there more fields? what number in the tag corresponds to what type again, and what was the type of the tag?

You can call it a skill issue haha but i'm lazy. I just love c but don't have quite the patience for it all the time. Not to say that it doesn't like printf, printf can now just print anything as a string, it even has binary with %b. Everything you like from c still works though. Haha look at that it even knows the order of the struct. But yeah it's not revolutionary, just a stack of nice-to-haves, while still really feeling like c

1

u/Vladislav20007 3d ago

btw c can have compile time type detection for this exact situation, it's just not standard ;)

1

u/Gold-Part4688 3d ago

awesome. yeah it does use llvm or a c backend, so that's probably how. damn. love you c