Earlier quoted context omitted.
The function that calls `new_point`, the value is moved. Similarly, consider the following case. struct Point a = new_point(); struct Point a2 = a; Assuming `struct Point` has a destructor, this would move `a` into `a2`, and prevent accesses to `a` after `a2` assignment, as `a` is no longer considered to be alive at this point. C++ has a wrong default of cloning instead of moving, but a new language could fix that.
So you’re looking for Rust with C’s syntax?
C-for-all: Extending C with modern safety and productivity features
81–90 of 143 posts
Re: C-for-all: Extending C with modern safety and productivity features
#82Re: C-for-all: Extending C with modern safety and productivity features
#83Earlier quoted context omitted.
> C - there's no magic Strict aliasing and weak typing say hello. > wysiwyg of high level -> asm Except neither GCC nor Clang compile even remotely predictable ASM. It's easier to predict OCaml assembly output than the GCC's one.
How is strict aliasing magic? How could you possibly define the meaning of accessing an object through an incompatible type since the type of an object determines how the compiler interprets its value? The bits stored in the object do not even necessarily correspond to a value for every type, after all. And that's not even considering the fact that there is a great deal of freedom wrt how implementations can represen…
- casting away types unsafely is required for many common patterns in C, including any form of runtime polymorphism
- basically anything involving numerics has a good chance of happily casting for you without asking you or telling you
Re: C-for-all: Extending C with modern safety and productivity features
#84Earlier quoted context omitted.
You can't say "one is bad, therefore the other is good." They can both be bad.
In which case you shouldn't paint one as the exceptional evil for doing the same thing, as is usually the case.
Re: C-for-all: Extending C with modern safety and productivity features
#85Plain C ought to be considered a legacy language and not used for new code. There is zero reason to prefer it over whatever style of C++ you'd like. If you want procedural struct-based C++, you can have that, but gosh, don't write C.
Re: C-for-all: Extending C with modern safety and productivity features
#86What does powered by Huawei mean? Are they what Mozilla is to Rust?
We aren't in as dire a situation here in Canada as Australia [0] seems to be, but there's a reason it was so difficult to serve that Huawei extradition.
[0]: https://www.news.com.au/national/victoria/news/its-a-police-...
Re: C-for-all: Extending C with modern safety and productivity features
#87Earlier quoted context omitted.
Who owns the return value of new_point?
The function that calls `new_point`, the value is moved. Similarly, consider the following case. struct Point a = new_point(); struct Point a2 = a; Assuming `struct Point` has a destructor, this would move `a` into `a2`, and prevent accesses to `a` after `a2` assignment, as `a` is no longer considered to be alive at this point. C++ has a wrong default of cloning instead of moving, but a new language could fix that.
The logic around it is still pretty complicated, since we’re talking about C++.
Re: C-for-all: Extending C with modern safety and productivity features
#88Earlier quoted context omitted.
The function that calls `new_point`, the value is moved. Similarly, consider the following case. struct Point a = new_point(); struct Point a2 = a; Assuming `struct Point` has a destructor, this would move `a` into `a2`, and prevent accesses to `a` after `a2` assignment, as `a` is no longer considered to be alive at this point. C++ has a wrong default of cloning instead of moving, but a new language could fix that.
Why is cloning rather than moving the wrong default?
If the struct contains a pointer, you need a kind of additional contract that says how the memory that is pointed to is going to be managed, particularly when it is going to be freed and by whom. And that is where move semantics establish a constricting convention that is intended to make that unambiguous.
Re: C-for-all: Extending C with modern safety and productivity features
#89Earlier quoted context omitted.
So you’re looking for Rust with C’s syntax?
Would be a big improvement on Rust.
- Variable types are changed to avoid ambiguity in lexing.
- Loops and conditionals require {}, which means the parentheses can be dropped on the condition and there’s no ambiguity about nested if’s and else’s.
What would you like improved?
Re: C-for-all: Extending C with modern safety and productivity features
#90Wow, this is quite a trainwreck. I think it's possible to improve C while keeping compatibility with C programs, but that's not how you should do it. I think an improved C would be quite useful, but you really should be careful with what you include it, and keep the language simple. A lot of functionality feels like added because it could be added (WTF are nested routines). This way lies worse C++. In particular, I w…
In C99 it looks like this:
struct Point {
int x;
int y;
};
struct Point new_point(int x, int y) {
return (struct Point) { .x = x, .y = y };
}