top | item 27563240

(no title)

vasama | 4 years ago

Migrating to a pointer-size-pair string representation would be a better use of one's time.

discuss

order

compiler-guy|4 years ago

And only works if you don't rely on any third-party libraries that take normal C strings.

Which is to say, is unrealistic for many programs.

pjmlp|4 years ago

Depends on much they value security, even std::string has an extra null for c_str() calls.

habibur|4 years ago

Send the pointer from the pair to 3rd party and not the pair itself. You lose the efficiency in 3rd party, but still retain your gain in your own code. Better than before.

tgv|4 years ago

You can use a library that also adds a trailing \O. I used it to interface C++.

Gibbon1|4 years ago

I swear part of the problem is with C there is a cargo cult prohibition against passing small structs by value.

pjmlp|4 years ago

The cargo cult goes beyond that.

The belief it was created alongside UNIX from the start, when it was used to port UNIX V4 into high level language.

Micro-optimizing each line of code as it is written, "because it is fast", without even bothering to use a profiler.

Even though lint was created alongside C to fix already known programmer faults using the language, in 1979, the belief that only bad programmers need such kind of tooling.

kzrdude|4 years ago

In other languages we create types for just about anything, and like you say, it's strange that we don't do this more in C.

b5n|4 years ago

It's not a cult, its just that the cases where the risks of passing by value would be worth any perceived advantage are so few that it just doesn't make sense to even consider it.

It's not like it's a flimsy tribal based claim, the guidance is solid.

saurik|4 years ago

It does suck that the usual 64-bit calling convention limits the size of strict passed by value to 64-bits :/.