I know how printf works, I have been using it for 40 years or so!
GCC does complain about that.
Yes, that (PRId64 etc) is little messy, but it works fine, is precise, and is portable.
Sounds like good idea. But not for me. I like C because I always know exactly what scalar types I am using at all times (so choosing a printf conversion specifier is pretty easy). Although decent modern compilers deal with printf() and its formats specially, I suspect that many simpler compilers do not and the format is just a string.
I guess you are saying that your language has a formatted I/O facility that is more powerful, more flexible, and more portable than printf() - yet is simple and clean?
Code: Select all
#define PRId8 "hhd"
#define PRId16 "hd"
#define PRId32 "ld"
#define PRId64 "lld"
I'm at a loss to understand what is stopping you from writing your own functions ?
What are you on about. Of course you change its behaviour by changing its inputsYou can make it do what you want by modifying its inputs. But doing that directly in C is fiddly and error prone.
Can I ask why? Do these other languages not have their own formatted I/O? or is their I/O not as capable as printf?
PeterO wrote:↑
18 Oct 2019 13:00
I'm at a loss to understand what is stopping you from writing your own functions ?
Code: Select all
print(a, b, c);
I do. But other people use C (and this started in a thread about C for beginners) and highlighting the problems can be useful, as well as looking at workarounds. (Actually, I improved the way printf could be used, inside one C compiler, by allowing the compiler to fill in the format codes. That shows what can be achieved, even if it's never going to be a standard feature.)If you don't like the way C does things then use something else .... Your moaning here is achieving nothing.
So as we suspected you're not moaning about printf at all, just your general dislike of C. It's hard to understand why you use it at all.sal55 wrote: ↑Fri Oct 18, 2019 2:47 pmYou can't write functions that work better than printf, because it needs language support. For example, consider a function that is called as:which prints an arbitrary sequence of expressions of arbitrary type. It can't be done in a low-level language without a raft of extra features, when you might as well just fix the print facility.Code: Select all
print(a, b, c);
SO why are you still moaning about something you don't use ?I do.If you don't like the way C does things then use something else .... Your moaning here is achieving nothing.
So this is all just concern trolling then ?But other people use C (and this started in a thread about C for beginners)
Code: Select all
T a;
printf("%...", a);
I've done several, all used as private in-house languages, and long before I came across C. So my perspective is somewhat different.Heater wrote: ↑Fri Oct 18, 2019 12:26 pmIf you want a better different, "better", language then create one. Better tackle all these UB's first else you are building you house on sand. At that point you have a very different language no longer backward compatible with C source. Javascript, Java, C#, Rust etc.
Of course I can use printf. But it's a pig. Especially when you are terrible typist and you are writing dozens of temporary printfs for debugging.When I recall the many happy (and frustrating) hours I spent getting my first ALGOL programs to work as a teenager I don't think the foibles of printf() are a big deal. You soon grasp how the simple case work and that is good enough to get you along way before you feel the need for something more complicated.
You're goading me into a reply now. You may not know what T is because it's not your type, if it's from imported code. Or it's not visible, or hidden behind macros. Or it's used in an expression which mixes types like this: T*U+V', and you want to print that value; what type is the result? Because you need to know the result type to get the right format code.
Stop and consider that the Rust language is even more strictly typed than C (Actually I would not call C strictly typed but that is another story) but in Rust you can do this:Stop and consider your moaning about a 47 year old strict type-based language and your complaint is that your shouldn't have to know the type
Code: Select all
$ cat hello.rs
fn main () {
let x: i32 = 10;
let y: f32 = 3.14159;
let z = "Hello";
println!("x = {}, y = {}, z = {}", x, y, z);
}
$ rustc hello.rs
$ ./hello
x = 10, y = 3.14159, z = Hello
By creating a whole new language... Which is not what sal55 thinks is the solution to his "problem"
In C2x I believe.
Its been done in an entirely new language, and I think Algol68 did it a very long time ago.
That's easy, but its a GCC extension.
That's great and all but it's not C. It's a new different language.That's easy, but its a GCC extension.