News for hackers. Stuff that matters.
Re:Fat pointers in C using libcello by dllu on Wednesday April 29, 2020 @04:10AM (#23016682)
huh. Interestingly, for "and", "or" and "not", iso646.h already defines C alternative tokens: https://en.wikipedia.org/wiki/C_alternative_tokens
Re:Fat pointers in C using libcello by eqvinox on Wednesday April 29, 2020 @04:11AM (#23016692)
I know :) ... but have you seen anyone actually use those? I'd be curious to get a pointer or two.
Re:Fat pointers in C using libcello by saagarjha on Wednesday April 29, 2020 @04:24AM (#23016773)
Twice: once for a CTF challenge that stripped out certain symbols, and one other time when I set up an emulator with a sketchy key map and didn’t want to bother figuring out what those symbols were mapped to.
Re:Fat pointers in C using libcello by ritter2a on Wednesday April 29, 2020 @06:43AM (#23017645)
I've only seen wrong use: CS students working on a project in C++, using "and" and "or" as identifiers (which their local MSVC compiler apparently was cool with) and then being surprised that the course's testing environment (using gcc) found some errors.
Re:Fat pointers in C using libcello by dllu on Wednesday April 29, 2020 @04:13AM (#23016709)
I have seen people coming to C++ from Python use "and", "or", and "not" in their if-statements :)
Re:Fat pointers in C using libcello by eqvinox on Wednesday April 29, 2020 @04:17AM (#23016733)
Hah - I kid you not, I have the reverse problem! I work a lot with both C and Python (embedded interpreter & CPython extensions) and whenever I switch from a stretch of C coding to doing some Python, I catch myself typing "&&" and "||" instead of "and" and "or" :D

(C is my "native" language, so it doesn't really happen the other way around, but that's just me)

But honestly, I'm pretty sure we can call iso646.h "fringe" ;)

Re:Fat pointers in C using libcello by int_19h on Wednesday April 29, 2020 @06:47PM (#23025470)
Curiously, & and | are occasionally useful in Python. They do work properly with booleans, so the difference compared to "and" and "or" is that you don't get short circuiting, which in some very rare cases you might not want. ^ is less useful because it's almost the same as != (except stricter about types) - but it documents the intent more clearly.
Re:Fat pointers in C using libcello by aloisdg on Wednesday April 29, 2020 @05:30AM (#23017186)
In programming languages, does we have something akin to a mother-tongue?
Re:Fat pointers in C using libcello by macintux on Wednesday April 29, 2020 @11:30AM (#23020399)
There’s a fair bit of debate about the impact of learning specific programming styles as your first language. Quite a few people would argue that learning functional programming first is a benefit to understanding the concept of state and how to write clean code, even if you end up using something less pure.

Certainly, speaking as someone brought up on imperative and later OO code, it took a fair bit of unlearning to understand functional programming, and I still have no clue about type theory.

Re:Fat pointers in C using libcello by jcelerier on Wednesday April 29, 2020 @06:52AM (#23017699)
what's the problem ? it's legal C++ (https://en.cppreference.com/w/cpp/language/operator_alternat...) and imho more readable than && / ||
Re:Fat pointers in C using libcello by eqvinox on Wednesday April 29, 2020 @08:50AM (#23018471)
We're talking about C here, not C++. The keywords don't exist in C unless you #include "iso646.h"
Re:Fat pointers in C using libcello by pjmlp on Wednesday April 29, 2020 @10:53AM (#23019974)
So what? Unless you include std...h you also need to use _Bool, _Complex and so forth, hardly much different.
Re:Fat pointers in C using libcello by int_19h on Wednesday April 29, 2020 @06:48PM (#23025478)
But the repo doesn't include them - it defines them itself.

Technically, I believe this is actually UB, just like any other #define for a keyword or an identifier from the standard library.

Re:Fat pointers in C using libcello by pjmlp on Thursday April 30, 2020 @02:49AM (#23028111)
I don't follow.

When I do #include <stdbool.h> it also brings the #define bool _Bool, a keyword from the standard library.

How is it UB?

Re:Fat pointers in C using libcello by int_19h on Friday May 01, 2020 @09:32PM (#23048295)
It's not UB to #include standard headers that do such things. It is UB to #undef or redefine them yourself, though. And it looks like <stdbool.h> gets an explicit exemption, at least in C11:

"Notwithstanding the provisions of 7.1.3, a program may undefine and perhaps then redefine the macros bool, true, and false"

I guess it's because defining these was so common even before C99. But there's no similar verbiage for <iso646.h>, so...

Re:Fat pointers in C using libcello by jcelerier on Wednesday April 29, 2020 @08:56AM (#23018525)
let me quote you the comment I was replying to :

> I have seen people coming to C++ from Python use "and", "or", and "not" in their if-statements :)

Re:Fat pointers in C using libcello by eqvinox on Wednesday April 29, 2020 @09:50AM (#23019140)
Yet curiously absent from that quoted comment is anything about it being a problem, which you nonetheless ask about. I wonder if more context or a more well-intentioned reading is the solution? ;)
Re:Fat pointers in C using libcello by jcelerier on Wednesday April 29, 2020 @10:38AM (#23019769)
I read and reread it and I honestly don't understand how it is possible to come up with an interpretation where that is not seen as an issue by the author