News for hackers. Stuff that matters.
Re:What does the ??!??! operator do in C? by vonwoodson on Wednesday October 05, 2022 @07:44PM (#33102637)
To be fair, and definitely a part of its appeal, the K&R is only 312 pages long. It covers the language and most of the standard library you’ll need.

As opposed to say, “Learn You a Haskell for Great Good! A Beginner's Guide” which is 881 pages and doesn’t even moderately cover the prelude.

Anyway, C is an amazing language and I keep a K&R on my phone as a pdf

Re:What does the ??!??! operator do in C? by 1-more on Wednesday October 05, 2022 @08:19PM (#33102872)
My copy of Learn You a Haskell ends on page 360 and the index is another 16 pages. Is this some weirdly shaped PDF of it with tiny phone-sized pages?
Re:What does the ??!??! operator do in C? by sli on Wednesday October 05, 2022 @08:34PM (#33102955)
According to its listing on the No Starch website[0], the PDF is (currently) 400 pages. I'm not a fan of that particular Haskell book but it's in no way even close to 881 pages.

[0]: https://nostarch.com/lyah.htm

Re:What does the ??!??! operator do in C? by bbarnett on Thursday October 06, 2022 @03:33AM (#33105516)
That's 800 pages double sided! Simply because the back side is blank, is no reason to nitpick.
Re:What does the ??!??! operator do in C? by tremon on Thursday October 06, 2022 @04:56AM (#33106095)
I don't get it. Wouldn't 800 pages double-sided require a PDF containing 1600 pages?
Re:What does the ??!??! operator do in C? by bbarnett on Thursday October 06, 2022 @08:14AM (#33107238)
Sorry, been looking at new cars, and salespeople have been explaining new car, extended warranties to me.
Re:What does the ??!??! operator do in C? by stonemetal12 on Thursday October 06, 2022 @09:33AM (#33107961)
400 single sided printed pages. If you are trying to inflate the page count that is 800 pages, but every other page is blank.
Re:What does the ??!??! operator do in C? by Kalq on Thursday October 06, 2022 @04:53PM (#33113958)
Why don't you like that book and which Haskell book would you recommend then?
Re:What does the ??!??! operator do in C? by vonwoodson on Wednesday October 05, 2022 @11:05PM (#33103874)
Could be, now that you mention it. Which, now, makes me wonder if my K&R is even shorter.
Re:What does the ??!??! operator do in C? by DonHopkins on Thursday October 06, 2022 @05:53AM (#33106382)
There's one thing that's usually true about every well used copy of K&R, and that's that it always opens up easily and by default to the page with the huge operator precedence order and associativity table, because that's the page everyone needs to refer to the most often, which is usually bookmarked, but in an old copy doesn't even need to be.

That says something about the C programming language design, that I as a deeply stack based FORTH programmer and explicitly parenthetical LISP programmer find horrible.

Re:What does the ??!??! operator do in C? by dahfizz on Thursday October 06, 2022 @08:31AM (#33107414)
Just use parentheses if you're doing many operations on one line? I've been programming in C for years and never had an issue with operator precedence.
Re:What does the ??!??! operator do in C? by falcrist on Thursday October 06, 2022 @09:54AM (#33108173)
There's a lot of exaggeration that goes on with certain fans of postfix systems when they talk about infix systems.

For example: I really like HP calculators, so I'm in several facebook groups for fans of RPN/RPL and HP specifically. Sometimes a few of them go way too far out of their way to try to demonstrate how inferior algebraic systems must be.

For the record, my copy of K&R wants to open into either section 7.6 or appendix B. No idea what this says about me, though.

Re:What does the ??!??! operator do in C? by michaelcampbell on Saturday October 08, 2022 @09:39AM (#33132191)
Indeed, different strokes for different uses. I "grokked" RPN pretty early in my career and use it for all my calculator stuff... only. infix for programming languages is equally comfortable for me. I still have to think and study quite hard the prefix LISP notation. I get it, it's just not internalized like the other 2.
Re:What does the ??!??! operator do in C? by DonHopkins on Thursday October 06, 2022 @09:57AM (#33108208)
It's not that YOU have any issues with it -- because you're perfect.

https://www.youtube.com/watch?v=fKHaNIEa6kA

It's about the poor people who read your code that relies on both you and them having perfectly memorized every single little detail of operator precedence and associativity, instead of simply and consistently using parenthesis.

Quick without looking: can you tell me what the precedence and associativity of the ternary ?: operator is?

The designer of PHP got it wrong (which isn't surprising given his proudly self proclaimed contempt towards computer science and incompetence at parser writing), but then millions of PHP programmers also learned it the wrong way.

https://en.wikiquote.org/wiki/Rasmus_Lerdorf

Do you really want any of those people who were corrupted by PHP messing around with your code, if you relied on it being one way, and they assume it works the other way?

It's not that you can't tell what it actually does, it's that you can't tell what the person who wrote it actually meant, which is more important than what it actually does, especially when it has bugs.

Don't do many operations on one line, AND do use parenthesis, AND do use indentation, with no exceptions except for very simple expressions. Take every opportunity to use vertical alignment to make symmetry and repetition obvious, like:

    sqrt((x * x) +
         (y * y))
Redundant parens, plus breaking expressions into multiple lines and indenting according to depth, unambiguously express programmer INTENT, so the reader doesn't need to wonder if the person who wrote it had a clue or was just showboating.

Just use parenthesis, and put a comment on it, sailor.

https://wellcomecollection.org/works/m33njwx3/items

My copy of The Little Schemer won't open to page 13 because of the jelly stains.

https://vpb.smallyu.net/[Type]%20books/The%20Little%20Scheme...

Re:What does the ??!??! operator do in C? by dahfizz on Thursday October 06, 2022 @11:05AM (#33109147)
What is with the gay sailor condom ad? You're being completely ridiculous.

I'm glad you enjoy Forth so much, I guess. I'm sure postfix will catch on any day now.

Re:What does the ??!??! operator do in C? by coldpie on Thursday October 06, 2022 @10:09AM (#33108346)
I agree, but I'm still cracking open that page when I'm reading someone else's code. I guess you work solo most of the time?
Re:What does the ??!??! operator do in C? by dahfizz on Thursday October 06, 2022 @11:07AM (#33109184)
Nope, I work on a team. I guess we all have similar instincts about what is readable.
Re:What does the ??!??! operator do in C? by mrguyorama on Thursday October 06, 2022 @11:56AM (#33109902)
I don't know what it is with C programmers and programming "terseness". It hasn't been the 60s since the 60s, and you have gobs of memory available, your source code can have syntactic sugar for the purpose of readability and the world won't end.
Re:What does the ??!??! operator do in C? by dahfizz on Thursday October 06, 2022 @12:54PM (#33110797)
Can you give an example of syntactic sugar in a modern language that makes order of operations a non-issue?
Re:What does the ??!??! operator do in C? by rdlw on Thursday October 06, 2022 @05:49PM (#33114533)
Parentheses
Re:What does the ??!??! operator do in C? by dahfizz on Thursday October 06, 2022 @05:55PM (#33114597)
Yeah, that's why I said

> Just use parentheses

Not sure what that has to do with memory usage..?

Re:What does the ??!??! operator do in C? by rdlw on Thursday October 06, 2022 @06:15PM (#33114815)
Just to clarify, I'm not the original person you replied to, and we all agree about using parentheses.

mrguyorama just implied that the only reason you would check the operator precedence chart would be to shave a few bytes off the size of your source code, which has not been a reasonable reason to do anything for many decades, and yet C programmers seem to like to do it anyway.

Re:What does the ??!??! operator do in C? by 1-more on Friday October 07, 2022 @01:18PM (#33124264)
These aren't syntactic sugar, but formatters. I rather like Ormolu for Haskell and elm-format for Elm. I occasionally type a bunch of parenthesis so that I'll for sure have the right order of operations. Then the format on save removes the redundant ones. It's delightful. The typecheckers and tendency to wrap primitives in a semantically significant constructor help with that.
Re:What does the ??!??! operator do in C? by belter on Thursday October 06, 2022 @07:59AM (#33107104)
Can I up vote for first paragraph, and down vote the second? :-)
Re:What does the ??!??! operator do in C? by benj111 on Thursday October 06, 2022 @08:14AM (#33107239)
Isn't that what brackets are for?

Well that's what I do. If you're having to look it up to write it, you're going to have to look it up to read it again down the line.

Re:What does the ??!??! operator do in C? by zh3 on Thursday October 06, 2022 @01:05AM (#33104572)
Just checked my first edition K&R (copyright date 1978, last page number is 228 (end of index) after which there is a single tearout page for other "High Quality C and Unix system titles" from Prentice Hall. There's also a front section that has about 10 pages in roman numerals (2 pages of prefix starting with 'ix') so about 240 pages total.

Page 1 starts: "Chapter 0: Introduction".

Re:What does the ??!??! operator do in C? by checkyoursudo on Thursday October 06, 2022 @05:27AM (#33106262)
Page 1? What, it's not zero indexed?
Re:What does the ??!??! operator do in C? by DonHopkins on Thursday October 06, 2022 @07:44AM (#33106994)
It looks like it's 1-indexed, but it core dumps when you get to the last page.
Re:What does the ??!??! operator do in C? by pjmlp on Thursday October 06, 2022 @04:10AM (#33105771)
Which is why most workloads bring POSIX for the ride as means to make anything actually usefull.
Re:What does the ??!??! operator do in C? by dahfizz on Thursday October 06, 2022 @08:34AM (#33107455)
POSIX is an OS API. You're complaining that C interacts with the operating system to do useful work? What language do you use that can do useful work without interacting with the OS?
Re:What does the ??!??! operator do in C? by pjmlp on Thursday October 06, 2022 @09:18AM (#33107828)
POSIX is the part of the C standard library in UNIX, that should have been part of ISO C as well.

It wasn't, so any C application that is more than a toy hello world with stdio, pings back into POSIX for any kind of meaningful work, that wants to stay cross platform.

Basically it the the C runtime library, that wasn't part of ISO.

I use JVM, .NET, Web and C++, not caring if the runtimes are bare metal or running on top of an OS, type 1 hypervisor, or whatever.

Re:What does the ??!??! operator do in C? by salawat on Thursday October 06, 2022 @09:38AM (#33108008)
>I use JVM, .NET, Web and C++, not caring if the runtimes are bare metal or running on top of an OS, type 1 hypervisor, or whatever.

If you're downloading a JVM binary, you're missing out on the build step. It's C dependent, friend. How do you think that VM interfaces with the OS? Go on. Try it. ldd the java executable.

It's libc all the way down. C itself is a sort of "VM" specification utilized to create the tools to run the tools to build the tools that make other high level languages possible.

Unless you create something entirely custom in platform specific assembly, you're running on C at some level.

Re:What does the ??!??! operator do in C? by dahfizz on Thursday October 06, 2022 @10:42AM (#33108814)
I don't think you really understand what POSIX is.

POSIX is an IEEE standard (example [1]). POSIX defines the Operating System API. You can see the C implementation of this API here[2].

> so any C application that is more than a toy hello world with stdio, pings back into POSIX for any kind of meaningful work

Simply calling printf relies on writing to a file descriptor. A "Hello world" application on linux uses posix. ANY hello world application uses posix. Even your Java Hello world App will call into the posix APIs. `System.out.println` isn't magic. It calls into the C posix implementation.

If you want to do anything in any language (write to files, create threads, allocate memory, network communication), you need to go through the OS. POSIX is what defines that OS interface.

> I use JVM, .NET, Web and C++, not caring if the runtimes are bare metal or running on top of an OS, type 1 hypervisor, or whatever.

So you use POSIX, you just don't think about it.

[1] https://standards.ieee.org/ieee/1003.1/7700/

[2] https://en.wikipedia.org/wiki/C_POSIX_library

Re:What does the ??!??! operator do in C? by arinlen on Friday October 07, 2022 @03:00AM (#33118245)
> POSIX is the part of the C standard library in UNIX, that should have been part of ISO C as well.

I'm not sure what you're trying to say. The Portable Operating System Interface (POSIX) is specified in an ISO standard, and basically specifies what a UNIX operating system's programmable interfaces are.

https://en.wikipedia.org/wiki/POSIX

POSIX also specifies stuff like "awk must be made available". Is that what you think the C programming language specifies?

Re:What does the ??!??! operator do in C? by metafunctor on Thursday October 06, 2022 @04:16AM (#33105815)
My Second Edition K&R (purchased in the mid-90s) is only 272 pages, including the index.
Re:What does the ??!??! operator do in C? by wiseowise on Thursday October 06, 2022 @12:47AM (#33104486)
Comparing C to Haskell is like comparing razor to laser scalpel.
Re:What does the ??!??! operator do in C? by bryanrasmussen on Thursday October 06, 2022 @01:55AM (#33104854)
And not just any razor, a really useful one!
Re:What does the ??!??! operator do in C? by pjmlp on Thursday October 06, 2022 @06:44AM (#33106672)
One of those that always cuts the user no matter how carefully they try to get hold of it.
Re:What does the ??!??! operator do in C? by benj111 on Thursday October 06, 2022 @08:19AM (#33107300)
No it's a tool.

I suppose you could compare it to a table saw. C is one without a guard or any other safety measures, so you need to be careful not to cut your fingers off. More modern languages have the guard and break etc.

For general use you probably do want all the safety bits, but occasionally it is useful to be able to take it off to do a weird cut on a weird bit of wood.

None of that necessarily means you will cut your fingers off though.