|
(for anyone, except C++ snobs)
Now I need to clean my screen - just spit all over it laughing. honestly, I did make the comment that there are people out there that code at a level I cannot even comprehend. I've come to call them "code witches" <--- I'm waiting to see if anyone follows the reference I read your description of what decltype does and I think, "hmm, I need to pass gas."
It's almost like some of the new "features" and auto is not new - 2010 ish raise areas of C++ to a meta programming language on it's own. Macros on steroids or something.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
There is a time and a place for it, and it's sometimes useful when doing some heavy Generic Programming.
Like, in theory if you had to design your own tuple type (I know std already has one, but ignoring that), the function to access a tuple's value might be an auto because it's difficult to even type out the template instantiation necessary for the return type, much less come up with it.
Another place I use it: In my graphics library you can define pixels with an arbitrary memory footprint. Different amounts of bits for different channels, like RGB565 or YUV888 etc. Because of the arbitrary nature of it the integer values for each channel may be a different type. For example, while a channel probably won't be more than a uint8_t can hold (8-bits) it might be (12 bits? uint16_t would be necessary)
Because of that, when I go to assign values from arbitrary pixel formats I don't actually *know* what type it is, other than some kind of integer of 64 bits or less (based on static_assert constraints). So I could always promote it to a uint64_t but that creates other problems when you have to cast down again.
So auto is what's for dinner.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
Maybe someone can point me to a reference or provide direct experience. I'm trying to lift a VC6++ application to VS2022. Originally targeted at Xp, this will need to run under Win10 and 11. So, I thought it would also be a good idea to get it into a modern development environment.
Well, the # of warnings I am suppressing is getting concerning, but I understand what the warnings are about. Then I ran into this line of code:
"ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw)"
pure mfc macro which generates "....cpp(66): warning C26454: Arithmetic overflow: '-' operation produces a negative unsigned result at compile time (io.5)."
Mousing over the macro, it expands to some hideous expression: "{ 0x004E + 0xBC00, (WORD)(int)((0U - 0U) - 12), 0, 0, AfxSigNotify_v, (AFX_PMSG)(static_cast<void (ccmdtarget::*)(nmhdr*,="" lresult*)=""> (OnCustomDraw)) },"
It's clear why the compiler is alarmed: "(WORD)(int)((0U - 0U) - 12)"
Am I just wasting my time here? I'm going to thunder on, but I'm starting to wonder if I'm going to run into so much nonsense like this that it calls into question if I'll have anything working at the end....
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
charlieg wrote: Then I ran into this line of code:
"ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw)"
pure mfc macro which generates "....cpp(66): warning C26454: Arithmetic overflow: '-' operation produces a negative unsigned result at compile time (io.5)."
Mousing over the macro, it expands to some hideous expression: "{ 0x004E + 0xBC00, (WORD)(int)((0U - 0U) - 12), 0, 0, AfxSigNotify_v, (AFX_PMSG)(static_cast<void (ccmdtarget::)(nmhdr,="" lresult*)=""> (OnCustomDraw)) },"
It's clear why the compiler is alarmed: "(WORD)(int)((0U - 0U) - 12)"
Am I just wasting my time here? I'm going to thunder on, but I'm starting to wonder if I'm going to run into so much nonsense like this that it calls into question if I'll have anything working at the end....
1. It's not a compiler but IntelliSense alarm.
2. Yes, you are just wasting your time here. Just don't worry if the real compiling doe not show it as an error.
|
|
|
|
|
thank you.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
"Waste of time"?
If you're having fun doing this I'd say it's never a waste of time (doing this). That said, I'm reading WORD and thinking "If I ever get back into developing that QBASIC code (of mine) in that project in C++ where I've already got executable stubbs of function tests (vastly complex mathematical calculations made in lengthy formulas (astronomical in the sense of astronomy itself)) pasted into the VS interface, line numbers included (before QBASIC includes!), I'll probably have to go through MFC VC6++ in the stackoverload and codeguru websites to do the conversions and encounter this very issue".
Do you mean DWORD? I think I get "0U" ...
I'll fire up VS now, sir ... (firing up vs now) ... "C26454" ... uhm ... hangon ...
|
|
|
|
|
I think something was mangled in the translation. I took: "Yes, you are just wasting your time here. Just don't worry if the real compiling does not show it as an error." which I took to mean not fret about the warning.
I really need to lift this code, and working with VS2022 is "interesting." I've never seen a compiler generate so many arcane errors due to a typo. At the moment, I am trying to figure out why VS2022 is upset with '_messageEntries': const object must be initialized. It really has nothing to do with _messageEntries (this is an MFC thing) but more to with an error a few lines up.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
Ok, sorry about that. I just stoked up VS2022 and looking in the help found the WORD initializer. Who knew? Although I guess I was on a "Joan of Arcadia" type of bender in my sarcastic musing, I've since settled on refraining from CP commenting for my own good and am turning over this new leaf by announcing it here in the C/C++/MFC forum where there's probably less of an iota of confusion not of my own making.
Tyll should be good. Again, sorry.
|
|
|
|
|
it's been a loooonnnggg time since I converted/upgraded a MFC application.
If I remember correctly, signature changed for a lot of MFC messages and callback functions.
you need to check the documentation for each of those messages.
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
tracked down the one thing that was plaguing me.
Documentation? f***, all I can find are useless Microsoft help articles that are just informational to the point of flying you into the mountain. Return me to the days of DEC, where one bookcase help the complete knowledge.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
well, you can just read the header files.
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
lol, true. But going into the mfc afx, etc header files where "those people" took macros to an art form (I'm being generous) is tedious.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
Hi there,
i have a question regarding C++ "language updates", to phrase properly what i want to know:
We currently have an external employee that codes C++ Libraries for us, which are used for "drivers" to ensure communication via Ethernet, USB and Bluetooth.
Those libraries are currently only available as 32 Bit dll's and therefore created a discussion after we found out that in some cases we would as well need them as 64 Bit.
To get to the point, said collegue also mentioned, that those libraries are ensuring a downwards compatibility to run on systems below windows 10 (which is our current limit of support), namingly they run even on Windows XP and probably further down, written with VS 2005 iirc.
Since i am .NET developer i can not really grab the necessity for doing so, nor estimate the potential "risks, flaws or performance" related topics comming up with that compatibility.
So i want to ask you if my concerns are correct or totally wrong, when it comes to using "very old" C++ instead of modernizing it and only ensuring runtime compatibility to "current" OS'es.
I personally feel that, since C++ get's updated every now and then, there must be a reason for doing so, as well as ofc improving the final produce that get's spit out by the compiler if your using newer (not newest) C++ Versions.
As a bonus, if someone could take the time to answer this as well, would you suggest, think about or deny switching code parts into C# and .NET which probably could be switched due to framework functionalities where we can rely on the stuff microsoft already has built in there?
As a note: We leave aside the fact that nobody else from the team would have hardware to continue coding or even compile this old stuff.
In any case, thanks alot for reading and / or answering.
Rules for the FOSW ![ ^]
MessageBox.Show(!string.IsNullOrWhiteSpace(_signature)
? $"This is my signature:{Environment.NewLine}{_signature}": "404-Signature not found");
|
|
|
|
|
This is really a broad topic.
I am only able to just write down few observations.
C++ language updates are not bug-fixes: they improve the language. If you are going to start from scratch a new project then using modern C++ is a real advantage. On the other hand, migrating an old big (working) project could be painful.
If you need a 64bit DLL , you colleague could probably build it without using newest C++ features. Maybe he can, at the same time, keep the existing 32bit DLL , two builds of the same code.
If Microsoft provides me the same functionality my mates code do, by no means I would continue using the latter.
Does the compatibility argument applies also to your .NET code? I mean, DLL compatibility with old OS s is useless if you cannot run the application on such systems.
My two cents.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Thanks for the answers, that lit up some dark corners for me.
His proposal is to do simply convert the necessery stuff for 64 bit aswell so he'll provide both for us, not changing or modernizing anything.
That's what i would have guessed, an example given, we have code for BLE communication in such a library, i know that Microsoft API or respectivly .NET has a lot of Code and Features provided for BLE communication. SO my idea was, since he knows both worlds, to take the effort and convert to .NET, at least the things that are possible, he wasn't happy...
No, i hope i mentioned it but our application is bound to another external application that standardises things. Therefore we are only supporting Win 10 and 11 because said "Frame Application" is only running on those two.
Thanks again for your answer
Rules for the FOSW ![ ^]
MessageBox.Show(!string.IsNullOrWhiteSpace(_signature)
? $"This is my signature:{Environment.NewLine}{_signature}": "404-Signature not found");
|
|
|
|
|
You are welcome.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
If you switch to 64 bits, you need to update the whole thing, including external libraries.
IMO, it's not worth it to convert to 64 bits unless you have real reasons for it (large datasets, hardware requirements... )
HobbyProggy wrote: We leave aside the fact that nobody else from the team would have hardware to continue coding or even compile this old stuff.
lol.
At that point, it's more a business decision than a technical decision.
Your company needs to decide if they want to spend money maintaining old code on old compilers or move everything to a recent compiler and making sure everything is continuously up to date
Good luck.
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
Thanks, i may need that
To answer your first statement, it is required for us to support 64bit and 32Bit, with .NET it's easy -> Compile for Any CPU and done. I know it's more complicated in C++.
Rules for the FOSW ![ ^]
MessageBox.Show(!string.IsNullOrWhiteSpace(_signature)
? $"This is my signature:{Environment.NewLine}{_signature}": "404-Signature not found");
|
|
|
|
|
As another has pointed out, the changes to C++ are mostly language extensions. For example, before C++-11, there was no auto or ranged for loops. Some of the language updates do address some defects in the standard, either clarifying the language or addressing a corner case.
Two things stand out:
1) going from 32 bit to 64 bit is rarely as simple as just changing the compiler flags. You may find that, particularly if you need to access hardware, you need to adjust data types. For example a long is 4 bytes in 32 bit land, but 8 bytes in 64 bit land, and if you're using structs you may need to adjust padding.
2) You seem to have a "key man" reliance. Worse, the key man is an external entity. Hopefully, you have an escrow arrangement so that in extremis, you're not in the situation where you have to stat from scratch.
It's not clear why the libs should need to be compatible with older versions of Windows. One reason might be is that the entity providing the library has other clients that need it. If you're the only client, then it might be time to review the deliverables, and update contracts/expectations accordingly.
"A little song, a little dance, a little seltzer down your pants"
Chuckles the clown
|
|
|
|
|
Thanks for that.
Yep, i just started there quite fresh as well but it seems i am, because of the tasks i was assigned to, the one that finally starts to clean up some old things. And yes, it'll be fun if something unexpected happens.
I'll keep the last bit in mind and will address this task to my superior.
Rules for the FOSW ![ ^]
MessageBox.Show(!string.IsNullOrWhiteSpace(_signature)
? $"This is my signature:{Environment.NewLine}{_signature}": "404-Signature not found");
|
|
|
|
|
HobbyProggy wrote: to ensure communication via Ethernet, USB and Bluetooth.
As described all of those currently exist without customization. One might also wonder if this custom stuff is secure. Specifically how is be being tested to insure that it is secure and will remain so.
HobbyProggy wrote: windows 10 (which is our current limit of support)
Windows 10 runs on 64 bit systems but it also runs on 32 bit systems.
HobbyProggy wrote: We leave aside the fact that nobody else from the team would have hardware to continue coding or even compile this old stuff.
Presumably the company at least has the source code.
And yes there are risks to the company in not insuring continuity in case there are problems.
|
|
|
|
|
jschell wrote: As described all of those currently exist without customization. One might also wonder if this custom stuff is secure. Specifically how is be being tested to insure that it is secure and will remain so.
Yep... Uhm ... exactly one of the first things i was asking when i heard that, on the plus side i was able to read the whole BLE traffic with a sniffer when i was asked to measure and verify time needed for updates over ble.
jschell wrote: Windows 10 runs on 64 bit systems but it also runs on 32 bit systems.
Yep, i should have mentioned we need both.
jschell wrote: Presumably the company at least has the source code.
And yes there are risks to the company in not insuring continuity in case there are problems.
I am also asking the question because i want to ensure that we will not be screwed if something funny happens.
All the info will be used to lay out a plan and strategy to not fall off the edge.
Rules for the FOSW ![ ^]
MessageBox.Show(!string.IsNullOrWhiteSpace(_signature)
? $"This is my signature:{Environment.NewLine}{_signature}": "404-Signature not found");
|
|
|
|
|
HobbyProggy wrote: that we will not be screwed if something funny happens.
You need not suggest anything 'funny'.
Heart attack. Fire. Tornado. Flood. Etc.
What happens to the company if those happen to that single person.
|
|
|
|
|
for(int i=0;i<3;i++)
{
vector<thing*> * Nodes = new vector <thing*>();
thing * Athing = new thing();
Nodes->push_back(Athing);
}
do I need to delete the vector once the work is done or this is not required?
How about the things stored inside the container, do I need to delete those too or calling clear() is enough.
for(int i=0;i<3;i++)
{
vector<thing*> * Nodes = new vector <thing*>();
thing * Athing = new thing();
Nodes->push_back(Athing);
Nodes->clear();
delete Nodes;
}
modified 9-May-24 9:22am.
|
|
|
|
|
Calin Negru wrote: do I need to delete the vector once the work is done?
for(int i=0;i<3;i++)
{
vector<thing*> * Nodes = new vector <thing*>();
thing * Athing = new thing();
Nodes->push_back(Athing);
//do stuff
Nodes->clear();
delete Nodes;
}
Yes, you do.
Since you created it (vector) with new then you need to delete the vector once the work is done
|
|
|
|
|