I love C where types are basically a suggestion rather than a rule
-
Dang! I chased FAR too many pointers! :laugh:
-
The cast operator is why I can cast my struct directly to an "array" of bytes and stash it in a file. It makes me happy. It's so elegant. So concise. And so dangerous.
Real programmers use butterflies
-
And I thought it was age that caused that "southern migration" of my hair. Not much on my head any more, but I think my ankles are getting hairier.
-
You've never really programmed until chasing a pointer problem.
I'm not sure how many cookies it makes to be happy, but so far it's not 27. JaxCoder.com
lol
-
That's the fun! Make a change and watch it break and fix the break is the only way to understand ancient code.
#SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
-
You misunderstand me. I'm not saying C doesn't enforce types. I'm saying if you want to change the type it's enforcing you just have to give it a little nudge. For example
struct S {
int x;
int y;
};...
S s;
s.x=1;
s.y=1;byte* bp = (byte*)&s;
// now i can work on it as a series of bytes
Real programmers use butterflies
Quote:
byte* bp = (byte*)&s;
That's a bug :-/. C does not allow conversion of pointers to anything other than a void pointer and back again. A compiler may let you do it but the language standard calls it a bug (undefined behaviour). In other words, that isn't correct C; many compilers will allow it and let the program produce unpredictable results (anything from producing the correct results, producing incorrect results, all the way to crashing). The correct way to do that is to use a union, at which point the strong typing gets enforced and alignment is guaranteed and you have not broken any of the C standards rules. While this way isn't Undefined Behaviour, it's not fully defined either - it's Implementation Defined (someone will correct me if I am wrong on this point, no doubt :-) due to padding that may or may not occur depending on what flags were given to the compiler. To be honest, any time you need to put in a cast in C (not C++) because the compiler is complaining, it's probably a bug. There are very few uses of casting in C (not C++) that aren't bugs. All uses of casting that I've seen in production code were alignment bugs. The few cases you need casting in C is when you are writing generic container functions and want to provide const guarantees to the callers. Also, 'byte' is not a type in C. You probably mean to use 'uint8_t' or 'uint_least8_t'. I've seen programs use 'char' for bytes, but that isn't correct either as the standard doesn't require 'char' to be unsigned or to be signed (it's left up to the implementation) and 'working' code will suddenly stop working if the program is recompiled on a compiler which defaults to signed char (left bitshift operations on signed integer types are undefined. It's only defined for unsigned integer types). I've been seeing more and more of this meme "C has weak typing" in various forums recently. In reality there is literally only one or two specific instances where the typing breaks down in C.
-
Everything is a pointer for your interpretation...
"The only place where Success comes before Work is in the dictionary." Vidal Sassoon, 1928 - 2012
And when it breaks, everyone will be pointing at it.
-
"Make a change and watch it break and fix the break is the only way to understand ancient code." While looking for a new job!
Well, I didn't say put it in production. But haha, that is a potentiality.
#SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
-
why would I want to take a giant leap backwards?
#SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
-
And I thought it was age that caused that "southern migration" of my hair. Not much on my head any more, but I think my ankles are getting hairier.
-
den2k88 wrote:
C++ is ... hard to read and often very hard to write
Am I using it wrong, because I've never had these problems?
“If we get $100,000, we will go to Potato blockchain.” Enable the dream!
-
You're probably not using all the "features". I've been tripping through some code that I have to study each line for 10-15 minutes to figure out what it's doing. I hate it!
My question: would it be understandable if it was rewritten using older features without the newfangled stuff, or is it only possible to do using the newfangled stuff? Can it be refactored to be easier to understand?
“If we get $100,000, we will go to Potato blockchain.” Enable the dream!
-
My question: would it be understandable if it was rewritten using older features without the newfangled stuff, or is it only possible to do using the newfangled stuff? Can it be refactored to be easier to understand?
“If we get $100,000, we will go to Potato blockchain.” Enable the dream!
No, in the case I am thinking about, it has to do with simple formatting so that the logic flow would be clear. It is a sequence of 30 or so if/elseif statements with embedded if's or if/elseif's with absolutely no indentation. Telling what elseif goes with what if is a pain in the patootie. But in other cases, I have seen lambdas embedded in templates which makes debugging old code very difficult on an easy day. My belief is simple: Code should be comprehensible for its intent and objective within a few seconds. Looking for matching braces, buried parens, etc. is very frustrating.
-
Understand. I've been trying to figure out why I have more hair growing out of my ears and nose that I have growing out of the top of my head. Near as I can figure, it's because the testosterone pump isn't as strong as it used to be.
-
The cast operator is why I can cast my struct directly to an "array" of bytes and stash it in a file. It makes me happy. It's so elegant. So concise. And so dangerous.
Real programmers use butterflies
Love you for bringing this up. Spent my best years doing C, starting on Atari ST. Now I'm lazy and use C++ (up to a point). Much more productive, owing mostly to other people's work (ashamed). Long live piraCy!
-
Love you for bringing this up. Spent my best years doing C, starting on Atari ST. Now I'm lazy and use C++ (up to a point). Much more productive, owing mostly to other people's work (ashamed). Long live piraCy!
Technically I'm using C++ but I forget because it's on a microcontroller and no STL so I find myself doing more c-isms than anything. :)
Real programmers use butterflies