|
Hopefully people will come to their senses and switch from C# to Java, just saying.
~d~
|
|
|
|
|
Sure, and then they can't do any of this. No structs, no spans, no layout control.
|
|
|
|
|
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
|
|
|
|
|
Exceptionally useful - you can do a cheap encryption by clever casting - or even more convenient, what might be considered an alias for casting: union
And if one so chooses, passing ones data through a logical cuisinart is always appropriate.
If you wish great power you must take great responsibility. As always.
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
I use unions sometimes, but i only needed the cast in two places in the code that inspired this post, and it was all it was ever going to need.
Real programmers use butterflies
|
|
|
|
|
I really liked being able to cast nearly anything to anything.
For a cheap and easy (and not too secure) 'encryption' I'd just do something like:
union {
char * readable;
ulong * notSoMuch;
} and then you can trivially make a string unreadable by storing the int array in a text file (lots of options there, too, spaced or other-delimiters? left-zero-filled?
Decryption is obvious - and really no overhead as all - I always though of it as the string and its encrypted version coexisting in different planes of their little universe.
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
I use the union technique for that in both C(++) and C#. I don't *always* use it in the former just because i hate declaring new types for one or two lines of code where it will be used.
i don't really believe in security by obscurity in most cases, but it may be useful for shrouding source code.
Real programmers use butterflies
|
|
|
|
|
Yes to all of that. Elegant and concise. C++ is much more type safe, and yet it became heavy: hard to read and often very hard to write, a bit constrictive.
C is absolute freedom, total power... and requires total responsibility.
GCS d--(d+) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++* Weapons extension: ma- k++ F+2 X
|
|
|
|
|
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?
|
|
|
|
|
Funny, I was thinking the same things. But then again, I've encountered code like the OP described. Usually written by electrical engineers.
#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 mean C++ that is no more than C or, even worse, FORTRAN?
|
|
|
|
|
Yeah, that too. But yes, c++ that was like trying to interpret sanskrit.
#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
|
|
|
|
|
Well, some of the template stuff out there...
|
|
|
|
|
When that becomes easy to read, you know you are a real programmer!
|
|
|
|
|
Neither did I, until I discovered I "was using it wrong" and had some "true C++ programmer" abusing templates lambda functions like there was no tomorrow.
GCS d--(d+) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++* Weapons extension: ma- k++ F+2 X
|
|
|
|
|
Ung! That sucks! I will admit that I'm not a great fan of lambda syntax, but I love what it is capable of. Putting them in templates - major Ungh!
I would classify that as template metaprogramming, rather than C++, just so I could live in my happy little C++ bubble!
|
|
|
|
|
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?
|
|
|
|
|
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.
|
|
|
|
|
Then there are unions. Essentially a compiler-driven cast with no type conversions what so ever. It's in-memory aliasing. It takes casting to an entirely new level. I have found many good uses for unions. So has Microsoft - see the LARGE_INTEGER for an example.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
|
|
|
|
|
Yeah, I'm aware - I even adapted the approach for C# using StructLayout.Explicit. It's just that declaring a union type isn't always called for. If you're doing the cast once or twice it doesn't make a lot of sense, so i do it when it's called for.
Real programmers use butterflies
|
|
|
|
|
yeah, that'll work so long as you don't stash your structs pointers this way.
#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
|
|
|
|
|
Yeah I try not to point into the stack for longer than the context of the containing function.
Real programmers use butterflies
|
|
|
|
|
No problem. Placement new to the rescue!
Sorry, wrong language.
|
|
|
|
|
Yeah, but that processing the struct after-the-fact. Her technique is great for 'simple' structs.
#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
|
|
|
|