Better HN
topnewbestaskshowjobs
Log inSign up

quelsolaar

3,298 karma · joined Oct 26, 2013 (13y ago) · 567 submissions

Submissions

comment 1w ago · link · parent

You cant in standard C, but many implementations do let you manipulate pointers in all kinds ow ways, but then your code depends on an extension of the language and is not portable. C is designed so that you can write both portable and non portable code. I would argue you shouldn't because often these extensions are very poorly documented and are based mostly on "it seems to work". Try when possible to stay within the standard.

comment 1w ago · link · parent

The argument that this is valid defined C is not entirely correct. You can not subtract one pointer form another that doesn't come from the same allocation, that is explicitly UB. But the user here subtracts one integer from the other and that is valid. However C only guarantees you can you can convert a integer to a valid pointer, if that integer has been converted from a pointer, and not been modified in any way. If the integer has been modified its implementation defined what happens. Its no longer valid standard C.

C supports pointers that can have memory banks, or pointers that are consist of a hash and and an offset. Real world hardware architectures like CHERI does this and standard C supports this. In hardware like that, this would break, even if the subtraction is done on integers, and don't violate the no subtraction of pointer of different allocation rule. So no, Pointers are really not integers, even if they may look like integers on your machine.

E (Member of the wg14 memory model study group.)

comment 1mo ago · link · parent

If you are trying to buy some place to live, it doesn't just matter how much money you have, it also matters if there are lots of people many times wealthier than you bidding for the same realestate.

More money doesn't create more things to buy or more people making things, its just means more money competing for the same things to buy. Other people having more does diminish your share, of the cake. Yes, we can make the cake larger, but the best way to do that is for more people to get more opportunity to fulfil their potential, by getting a reasonable share to do so.

comment 2mo ago · link · parent

One a modern computer, the ideal integer type is usually smaller than 64 bits. Even though the arithmetic units handle 64 bits in one op, 64 bits take up twice the memory bandwidth, and half as many fits in a cache-line, and given that a modern computer is usually bound by memory access, smaller is better. So you can argue that both new and old computers prefer 32 bit over 64, but for different reasons.

The added compatibility between 32 and 64 bit systems, is another reason. Also if you choose int to be 64 bits, what would you make short? 16 or 32 bits? It makes much more sense to keep int 32 bits, and reserve long / long long for 64 bits.

comment 2mo ago · link · parent

That's not true. All the basic types have minimum sizes, so its perfectly reasonable to write software that stays within those bounds. You can avoid any overflows if you know the minimum limits.

comment 2mo ago · link · parent

At the time its was probably very hard to know what the fixed sizes should be.

comment 2mo ago · link · parent

Good article.

C would probably not have survived unless it had this flexibility.

But its not justa historical thing. Today there are modern platforms like DSPs that have 32bit sized char, because that is the smallest addressable type. These platforms depend on C for tool chains, even if most "portable" C wont run correctly on them. The fact that you can build hardware like that, and not have to invent a new language / dialect to program them is a huge win for the world.

<edit> I didnt see the footnote about DSPs at first read </edit>

comment 6mo ago · link · parent

I was luck to know Josh Nimoy who is responsible for a lot of this in the movie, who has since sadly passed away. Josh took great pride in the fact that he was able to put Emacs and a bunch of Unix commands in a major Hollywood blockbuster.ed

comment 6mo ago · link · parent

The things you want from C isn't C. Id advice you to use another language.

comment 6mo ago · link · parent

A lot of the Central UB can not be defined, because they rely on detection. In order to have a well defined behaviour (by the standard or the compiler) the implementation needs to first detect that the behaviour is triggered, this is often very tricky or expensive. Its easy to define that a program should halt, if it writes outside an array, but detecting if it does can be both slow and hard to implement. There are implementations that do, but they are rarely used outside of debugging.

A better way to think about UB is as a contract between developer and implementation, so that the implementations can more easily reason about the code. How would you optimize:

(x * 2) / 2

An optimizer can optimize this out for a signed integer, because it doesn't have to consider overflow, but with a unsigned integer it can not. UB is a big reason why C is the most power efficient high level language.

comment 6mo ago · link · parent

The 5 stages of learning about UB in C:

-Denial: "I know what signed overflow does on my machine."

-Anger: "This compiler is trash! why doesn't it just do what I say!?"

-Bargaining: "I'm submitting this proposal to wg14 to fix C..."

-Depression: "Can you rely on C code for anything?"

-Acceptance: "Just dont write UB."

comment 8mo ago · link · parent

Mark down is great because it doesn't define a bunch of things. Headline? Its a headline, no font, no sizing, no colors... Just a headline. It means that it can be displayed on any device, printed on any paper, work with any accessibility tool and optimized for what ever requirements the reader has, not what ever the writer thought looked good. The web is full of great content being made hard to access because of poor/inflexible layout choices. Just give me the text and let me choose how to make it readable. The added fact that you can read raw markdown without even parsing it makes it even better. Not having total control over what its going to look like for the reader is a feature not a bug.

comment 8mo ago · link · parent

Do not make the mistake of anthropomorphising Larry Ellison.

comment 11mo ago · link · parent

This, "If you have enough, why does it matter if someone else has more" argument doesn't really hold. Yes we can make more TVs and phones so that everyone can get one, but then get to things like centrally located housing, where there is a limited supply. It matters a lot if you want someplace to live, and there are thousands of very rich people trying to out bid one and other for the same space in your city. This is why housing is no longer affordable.

comment 12mo ago · link · parent

Thanks for the shout out. I had no idea my 2h video, without a camera 8 years ago would have such legs! I should make a new one and include why zero initialization is bad.

16.

Undefined behaviour spotted in safe Rust code(twitter.com ↗)

2 points · by quelsolaar · 1y ago · 1 comment

comment 1y ago · link · parent

Yeah the idea i that school is somehow a bastion of meritocracy is misguided.

Academia is better at setting clear requirements and measuring those goals, but whether these requirements have anything to do with being successful or useful in the real world is an entirely different matter.

School isn't reality, its mostly not even trying to simulate reality. School breads a lot of "Why was I not rewarded? I did everything they said i should do" disappointment in the real world.

comment 1y ago · link · parent

This is awesome. I run a team that uses software I produce and i have a rule that i can’t deliver breaking changes, and i cant force migrations. I can do the migration myself, or i have to emulate the old behavior next to the new. It makes you think really hard about releasing new APIs. I wish this was standard practice.

comment 1y ago · link · parent

Writing in binary or cranking your own electricity is easy. Anyone can do it.

There is a difference between things that are difficult and things that just take a lot of work.

comment 1y ago · link · parent

Your customers will pay more for things that are hard to do. Ask ASML.

comment 1y ago · link · parent

I exclusively write in C89. I'm a member of the ISO C standard board.

comment 1y ago · link · parent

When ever i see "never implement your own...", i know i want to implement it myself. People say that about hard things, and I only want to do hard things. Nobody wants people who can do easy things, people want people who can do hard things. The only way to learn how to do hard things, is to do hard things, so do the hardest things.

So go ahead, write your own date library, your own Unicode font rendering, compiler, OS, game engine or what ever else people tell you to never do because its hard.

23.

Better Software Conference: Finish Your Software [video](youtube.com ↗)

7 points · by quelsolaar · 1y ago · discuss

comment 1y ago · link · parent

Maybe the victims of gunshots wanted to be shot? People shoot themselves all the time.

Should we make convictions of murder, depndent on proving that the victim dint actually want to get shot?

comment 1y ago · link · parent

Yeah thats an old idea, that have proven again and again to cause misery. Its not flimsy at all. Its peer reviewed science.

comment 1y ago · link · parent

Yes, Sex work can be made more safe. However none of these protects against the psychological harm that may sex workers are experiencing. There is plenty of evidence how harmful prostitution can be to mental wealth.

You list things that regulated to protect the user of drugs, tobacco and alcohol, but with prostitution, the product is a human being that needs to be protected too.

The Nordic model, does not outlaw selling sex, but criminalizes buying. In my opinion, selling sex may be harmfull, but i see no ethical reason against it. However there is no ethical way to buy sex, because its impossible for a buyer to be sure that you are not causing serious harm to the person you are buying from.

comment 1y ago · link · parent

We want to protect vulnerable members of society. they come in all sizes and shapes.

comment 1y ago · link · parent

I'm saying that hiring people to do a job that is extremely dangerous, and likely to cause the worker harm, especially for your own enjoyment is exploitative.

Most of the jobs you list are FAR safer then prostitution. But yes I would argue there are lots of other jobs that i would outlaw for the same reason. Like Bumfighting, a lot of dodgy construction, self harm, jobs without proper safety equipment, gladiators, and a lot of military recruitment. You are exploiting, or are very likely to be exploiting people in dire situations.

comment 1y ago · link · parent

I'm ok with outlawing adults with free wills, getting payed to play russian roulett even if five out of six wont take a bullet to the head. Adults can be exploited too.

"neither harmful", tells me you know nothing about the subject.

12345
19