Home » Extra libraries, Code snippets, applications etc. » C++ language problems and code snippets » Make THISFN simpler and more powerful (by taking advantage of some new c++ feature)
Re: Make THISFN simpler and more powerful [message #60927 is a reply to message #60926] |
Wed, 09 October 2024 16:09   |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
I don't like that fact that compilers are allowed to stuff random padding bits in a bitfield as they like, but it's actually standard compliant.
In the above example, change unsigned to byte (Upp::byte of course) actually removes the extra cost on total storage usage. But the padding MSVC inserts vs GCC's sequential packed bits will result in binary incompatibilities. Worse, some old c tricks no longer work with MSVC.
A somewhat more realistic though simplified example.
class SomeFormat{
...
private:
Font font;
Color paper, ink, highlight;
union{
int32 dummy;
struct{
byte info1:3;
byte info2:5;
// allow individual font properties
// to be Null for multi-tier composition
bool faceNotNull:1;
bool heightNotNull:1;
bool widthNotNull:1;
bool boldNotNull:1;
bool strikeoutNotNull:1;
bool underlineNotNull:1;
bool italicNotNull:1;
};
};
};
In old c days, if we want to check if all Font properties are set, we can simply
bool SomeFormat::AllFontPropertiesSet()const
{
#define SOMEFORMAT_MASK (((1<<7)-1)<<8)
return (dummy & SOMEFORMAT_MASK) == SOMEFORMAT_MASK;
#define SOMEFORMAT_MASK
}
And to mark all font properties as set(non-Null)
SomeFormat::SetAllFontProperties()
{
#define SOMEFORMAT_MASK (((1<<7)-1)<<8)
return dummy |= SOMEFORMAT_MASK;
#define SOMEFORMAT_MASK
}
etc. With GCC, you can still do things like that. Total predictability. Fully appreciated.
End of the day, what benefits MSVC is going to achieve by padding random bits? I can see if a bitfield crosses a machine's fast-integer boundary (a few bits in previous FAST-INTEGER and a few in the following), there will be extra cpu cost involved. Other than that, what's going to be saved?
Thumbs down for MSVC on this regard.
[Updated on: Wed, 09 October 2024 16:12] Report message to a moderator
|
|
|
 |
 |
Make THISFN simpler and more powerful
By: Lance on Tue, 18 October 2022 21:08
|
 |
|
Re: Make THISFN simpler and more powerful
By: Lance on Thu, 10 November 2022 00:32
|
 |
|
Re: Make THISFN simpler and more powerful
By: Oblivion on Thu, 10 November 2022 06:29
|
 |
|
Re: Make THISFN simpler and more powerful
By: Lance on Thu, 10 November 2022 12:52
|
 |
|
Re: Make THISFN simpler and more powerful
By: Lance on Thu, 10 November 2022 21:41
|
 |
|
Re: Make THISFN simpler and more powerful
By: Lance on Fri, 11 November 2022 02:50
|
 |
|
Re: Make THISFN simpler and more powerful
By: Lance on Tue, 08 October 2024 18:38
|
 |
|
Re: Make THISFN simpler and more powerful
By: Lance on Tue, 08 October 2024 18:42
|
 |
|
Re: Make THISFN simpler and more powerful
By: Didier on Tue, 08 October 2024 19:25
|
 |
|
Re: Make THISFN simpler and more powerful
By: Lance on Tue, 08 October 2024 20:01
|
 |
|
Re: Make THISFN simpler and more powerful
By: Lance on Wed, 09 October 2024 05:59
|
 |
|
Re: Make THISFN simpler and more powerful
By: Lance on Wed, 09 October 2024 16:09
|
 |
|
Re: Make THISFN simpler and more powerful
By: Lance on Wed, 09 October 2024 16:17
|
 |
|
Re: Make THISFN simpler and more powerful
By: Didier on Wed, 09 October 2024 19:32
|
 |
|
Re: Make THISFN simpler and more powerful
By: Lance on Thu, 10 October 2024 14:01
|
 |
|
Re: Make THISFN simpler and more powerful
By: Lance on Thu, 10 October 2024 14:06
|
 |
|
Re: Make THISFN simpler and more powerful
By: Lance on Tue, 05 November 2024 02:25
|
 |
|
Re: Make THISFN simpler and more powerful
By: Lance on Tue, 05 November 2024 02:33
|
 |
|
Re: Make THISFN simpler and more powerful
By: Lance on Thu, 07 November 2024 00:49
|
 |
|
Re: Make THISFN simpler and more powerful
By: Lance on Fri, 29 November 2024 02:30
|
Goto Forum:
Current Time: Sat Jul 05 03:30:22 CEST 2025
Total time taken to generate the page: 0.04437 seconds
|