The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
Your 3 byte integer problem is exactly the kind of work-around that causes problems. I like your solution to the LE problem--simple and directly understandable.
But, what if we didn't have to think about it? What if the variable could be defined as "3 byte little endian integer" and the conversion to/from machine requirements took place automatically on all future references? How could something like that be implemented at the language, compiler or machine level?
I cannot tell you how many times I've seen "char" definitions used inappropriately when a "byte" definition would make more sense. Or things like:
But we already have that! Let's forget the 3-byte-integer for a moment, that's rather specific to that protocol and usually not needed. When I work with a int32_t (a rather common type), I don't have to care which endianness the underlying system uses. The compiler takes care of everything! Same goes for, let's say, uintptr_t. I don't have to care about endianness, bitness, none of that. The compiler does it for me. Well, I of course have to work with the compiler, but your world, the one where the programmer doesn't have to care, is already there.
The other topic here is that people will always find a way to circumvent the compiler and shoot themselves in the foot.
There's languages that make that easier or harder, C is the worst offender I've ever met (save for assembly, but that's in a league of it's own). C doesn't even have a byte type! A char is a byte in C, you can't blame the programmer (except for possibly poor choice of C as a tool). Switch the language. C# or Delphi on the other hand, those compilers yell at you when you're doing questionable things. And if that thing in question may work just fine while still remaining questinable, you'll at least get a warning.
Feel free to yell BULL, by the way. I've never done such a thing because the question is not whether it'll blow up in my face but a mere when. It will blow up sooner or later.
Fun fact: I've now spent about two weeks fixing a binary communication layer. Some predecessor of mine thought that using strings, data structures designed for text, where binary information is processed, would be a splendid idea. And then came Unicode. Trying to convert 99h to a Unicode string member yields 3Fh and some other byte I've forgotten. I bet it was a C programmer who grew up in the 60s riding the "Learned it once, never relearn"-mentality. Converted all of this nonsense to TArray<Byte> (Delphi nomenclature) and stuff works now.
I still wonder whether your topic is about programming in general C in particular as you seem insistent on issues that are long solved by several programming languages (granted, both Delphi and C# still allow you to shoot yourself in the foot, but you gotta fight hard against the compiler to do that).
Seriously though, the problem is that as a profession we have no real enforced standards. Microsoft attempted to be a standard bearer in the 1990s and early 2000s but everyone complained and now we have the morass that technicians are just starting to rightly complain about.
The other issue is that we have too many technicians in our ranks that are too eager to promote their own vision of things at the drop of a hat since using a tool that may be one or more years old may not be cool.
First the major organizations destroyed the vital functions of IT development and then the technical community got on board and started doing the job for them.
Now you have aberrations like MVC replacing Web Forms when it was already available and no one on the Microsoft side of things was interested until that company promoted its own version of MVC (most likely a direct copy of the original).
Now you have Agile and DevOps, which in reality are diametrically opposed to quality software engineering standards.
And now you have new tool-sets being introduced on a daily basis by anyone who thinks they know what they are doing.
In short, the entire profession is a complete mess.
And it ain't going to get better in the current economic environments of barbaric capitalism...
Sr. Software Engineer
Black Falcon Software, Inc.
How many times have you heard a senior management type say "We need it to run on Windows laptops for Accounting but Marketing uses Macs and Engineering uses Linux. And by the way, can you make it accessible from my phone?"
If I had a nickel for every time I've heard that, I would make Bill Gates and Warren Buffet combined look like paupers.
For years the image of developers has been the living in their parent's basement, never sees the light of day, lives on sodas and pizza.
For many, I am sure this might actually be accurate (I know at least one person who precisely matches this description - he used to write video codecs for fun).
For the rest of us I am sure travel and enlightenment (and occasionally family) are just as important. I have worked and lived in five countries and visited many more. Here are my lists:
Lived in: England, Sweden, Germany, France, USA
Additionally visited: Austria, Belgium, Netherlands, Czech Republic, Switzerland, Italy, Monaco, Scotland, Wales, Tunisia, Barbados, Jamaica, Grand Cayman, Crete, Corfu, Hong Kong (deployed - didn't see the city), Luxemburg, Lichtenstein, Mexico, Canada and sundry US States.
Bucket list: New Zealand, Iceland, Russia (maybe), India, Hong Kong (now it's no longer British), Norway, Denmark, The Moon (low-gravity retirement home). ...and Japan.
Where have you worked/lived/visited/been deployed?
- I would love to change the world, but they won’t give me the source code.
I live in the Netherlands and I've been to Iceland, Norway, Sweden, Finland, Russia (Sint-Petersburg), Estonia, Ireland, Wales, Scotland, Belgium, Luxembourg, Austria, Czechia, Slovakia, Poland, Hungary (Budapest), Slovenia, France, Italy, Spain (Barcelona), Madeira (does that count as Portugal?), Tunisia (Tunis), Malta, Greece, Israel, Kenya (where the giraffes are and the zebraaaas, forget Norway!), Indonesia, Canada, Costa Rica, Suriname and Cuba.
Not in that order.
Now that I'm counting them that's one country a year on average since I'm born (I'm 31)
And, my favorite country of them all, Germany!
It's beautiful, it has mountains, forests and plenty of castles and, huge bonus, it's relatively close to home!
Perfect for a couple of days out of the house
According to TripAdvisor I've seen 18% of the world...
Japan and New Zealand are on my bucket list.
I did became a computer addict in my parents house (no basement, but used the most remote room and the attached - closed - balcony)...
Lived only in Hungary and Israel so far, but visited in England (London only), France (south, along the Spanish border), West and East Germany, Italy (Milan), Poland, Czech Republic, Romania, Yugoslavia, Bulgaria...
I do not plan to visit places abroad for now... There are a lot of places nearby that I want to see (and show to the kids) before that...
"The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge". Stephen Hawking, 1942- 2018
lived in: England, Germany, Canada (4 months), Northern Ireland, technically Australia but I was delivering software to someone in an airport.
Visted: Italy, Czech republic, Spain & islands, Portugal
Bucket List: St Petersburg, Caribbean, Various places in the USA, Japan, China, New Zealand, Australia, Sweden and other nordic regions
I have lived in various places in Germany but that was due to my father being in the armed forces and got to see Berlin before the wall came down, as the wall came down and immediatley after. But would love to visit again.
Every day, thousands of innocent plants are killed by vegetarians.
Where have you worked/lived/visited/been deployed?
I've lived in the USA, Venezuela, Mexico and Bolivia and visited Aruba, Ecuador, Colombia, Suriname, Brazil, Argentina,Peru, Canada,England, The Netherlands,Malaysia, Indonesia, Japan, Hong Kong, Singapore, and likely a few other places.
I have a trip to Malaysia in the works later this year and will return to Venezuela as soon as the situation there stabilizes.
In addition, besides taking time off when
I had a stroke, I completed my PHD, sdo I've managed to get out and stay busy.
CQ de W5ALT
Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software
Lived in: New Zealand, New York, Paris, Sydney, Melbourne
Visited: Singapore, Indonesia, Malaysia, Thailand, Laos, Cambodia, Viet Nam, Hong Kong, China, Fiji, India, Croatia, Hungary, Czechoslovakia, Spain, Germany, Italy, England, Netherlands, Sweden, Norway, Latvia, Russia (trans-Siberian train trip), Canada, Mexico, Peru, Chile, Argentina (5 months in South America, 10,000kms on a motorbike) and Antarctica.
Haven't been to Africa yet, and would love to spend more time in Europe. Problem with living back in NZ is everywhere is so far away.
Oh, and I've seen NZ on bucket lists - drop me a note when you've got plans to come visit.