Earlier quoted context omitted.
No I don't want to throw it out, I kinda like C. And you can also do seemingly weird things with it. I was trying to bring some light to how const and immutable could be conflated. A lot of people see const and think, no aspect of this is changeable.
His point was that you aren't interpreting the `const' the same way the compiler does. To the compiler, this: const int *a; a = NULL; // perfectly OK *a = 0; // does not compile Is a pointer to a constant int, not a constant pointer to an int. You're probably confusing it with this: int *const a; a = NULL; // does not compile *a = 0; // perfectly OK Which is a constant pointer to a regular int. Of course you can comb…
Fixing C
101–110 of 123 posts
Re: Fixing C
#102Earlier quoted context omitted.
If it's embedded code, it's quite possible you can't just decompose code into little bitty chunks to avoid nesting, because your maximum stack depth is fixed and very small.
It is also definitely possible to go overboard with chopping up your code. I'm sure everyone has read that file where damn near every single line ended up in its own little function (in its own file with some big framework around it) and you're jumping all over the place trying to figure out what its actually doing. Everything should be made as simple as possible, but not simpler.
Sounds like node and its moronic packaging ecosystem.
Re: Fixing C
#103Earlier quoted context omitted.
No I don't want to throw it out, I kinda like C. And you can also do seemingly weird things with it. I was trying to bring some light to how const and immutable could be conflated. A lot of people see const and think, no aspect of this is changeable.
If you think that though, you haven't got a clear picture of what pointers are and how they work. The pointer itself and thing it is pointing to are two completely different variables in memory. Being unclear about the difference is likely to cause lots of problems when coding C. Using a pointer to iterate through a string/array/other data structure, that is stored in const is a completely standard thing to do.
Re: Fixing C
#104Closures. This is the only thing that I miss in C. I always want to declare local functions, and return pointers to them.
That would require implicit heap allocation, which is a lot to ask for in a language where malloc is a library function.
Re: Fixing C
#105Earlier quoted context omitted.
There you go: struct much_improved_c { ... }; struct much_improved_c an_api_that_doesnt_suck() { ... };
This is the only way it can be done in statically typed language. You cannot have multiple returns without defining how many there are what are their types.
Re: Fixing C
#106Of all the things in C that cause problems and that could be fixed by waving a magic wand, the author chose "curly braces"?! That betrays an immense lack of imagination! Worse, it shows that the author isn't even aware of the actual causes of lost productivity and bugs in C programs. What about buffer overflows (it happens to the best of us)? Mounds of undefined behavior exploited by optimizing compilers (even in see…
I've always wanted a heap inspection function. Give it a pointer and it returns the amount of data allocated to it. I mean free() can figure it out, why can't I see it? I'm sure there are some good technical reasons that make this difficult/expensive, but there aren't even any half measures available. Not even something that requires the pointer be at the start of the originally malloc()ed memory and can return an er…
http://stackoverflow.com/questions/1281686/determine-size-of...
Re: Fixing C
#107Re: Fixing C
#108Why don't we get rid of the semi-colon and delimit the line of code via the symbol EOL, or maybe use the carriage return.
Re: Fixing C
#109C, to me, requires a lot of discipline about good coding style and conventions. I personally like that a lot, even though, of course, it sometimes causes one to shoot oneself in the foot. But, and I can't point to exactly why, I don't think I want to change anything. Maybe Rust or something new will come along sometime soon to fix all the issues that exist with C. Oh, and for those who haven't seen it, there was a co…
I personally like that a lot, even though, of course, it sometimes causes one to shoot oneself in the foot. But, and I can't point to exactly why, I don't think I want to change anything. I feel much the same way, and I think it's the general principle of freedom over security that makes it fun . You can do lots of things that other languages wouldn't allow, and despite not needing to most of the time, the fact that…
That's okay, just please don't have this attitude while writing production code. If my system is compromised because of yet another buffer overflow exploit in some C library, I don't care if you felt the wind in your hair while programming it.
Re: Fixing C
#110Earlier quoted context omitted.
That would require implicit heap allocation, which is a lot to ask for in a language where malloc is a library function.
Not all closures require heap allocation.