I love C where types are basically a suggestion rather than a rule
-
C# has been improving a lot in that area. You can take a `Span` of various types (some mostly-reasonable restrictions apply) and use `MemoryMarshal.AsBytes` on it to view it has a `Span`, then stash it in a file or whatever. It's nice. Actually paradoxically it's nicer than in C, because in C# you can actually control the layout of fields to whatever degree you need, so you can use this for file headers that have "unaligned" fields. C# is a better low level language than C.
Does it mandate the endianism and take the hit on non-compliant platforms, or is it still a problem for intersystem messages?
Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing. -
[Program: Shoot in foot](http://www.personal.psu.edu/sxt104/program1.html)
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.
Quote:
Assembler: You try to shoot yourself in the foot, only to discover you must first invent the gun, the bullet, the trigger, and your foot. Modula2: After realizing that you can't actually accomplish anything in this language, you shoot yourself in the head.
:laugh: :laugh: :laugh: :laugh: :laugh: :laugh: :laugh: :thumbsup::thumbsup::thumbsup::thumbsup:
M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.
-
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
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
-
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
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?"
-
Does it mandate the endianism and take the hit on non-compliant platforms, or is it still a problem for intersystem messages?
Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing. -
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
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
-
Unfortunately it's always in the native endianness, with no way to control it. An attribute for that is on my wishlist.
The proprietary language in which I worked for many years standardized its endianism and took the hit, so intersystem messaging was easy. It was designed when memory was precious--unlike today :)--so it was easy to control packing. For example, a
bool
was a single bit, and anenum
could be packed into the fewest bits needed for its enumerators (negative values not allowed). We would only pad a field when performance was critical.Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing. -
Member 14732673 wrote:
In the end i left it alone.
Really wise. Never touch a running system, unless you really know how to fix it :rolleyes: ;P :-D
M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.
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
-
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. :laugh:
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?
“If we get $100,000, we will go to Potato blockchain.” Enable the dream!
-
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!
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
-
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
:laugh: You mean C++ that is no more than C or, even worse, FORTRAN?
Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing. -
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!
Well, some of the template stuff out there... :wtf:
Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing. -
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
No problem. Placement
new
to the rescue! Sorry, wrong language. :laugh:Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing. -
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
the file is also not compatible between architecture to the next! :( i.e. endianess for sure.. but probably computer struct paddings too! :/ though haven't used C in decades, so I am not so sure about that one...
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
the file is also not compatible between architecture to the next! :( i.e. endianess for sure.. but probably computer struct paddings too! :/ though haven't used C in decades, so I am not so sure about that one...
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
Sometimes that doesn't matter. Sometimes you're writing software dedicated to a particular microcontroller and it expects the thing to be wired a certain way in order to run anyway.
Real programmers use butterflies
-
Sometimes that doesn't matter. Sometimes you're writing software dedicated to a particular microcontroller and it expects the thing to be wired a certain way in order to run anyway.
Real programmers use butterflies
oh well.. yes if consumer and producer is the same one, I guess it's all good! :)
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
Well, some of the template stuff out there... :wtf:
Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing.When that becomes easy to read, you know you are a real programmer!
“If we get $100,000, we will go to Potato blockchain.” Enable the dream!
-
:laugh: You mean C++ that is no more than C or, even worse, FORTRAN?
Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing.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