Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 #60925 is a reply to message #60924] Tue, 08 October 2024 20:01 Go to previous messageGo to previous message
Lance is currently offline  Lance
Messages: 656
Registered: March 2007
Contributor
Didier wrote on Tue, 08 October 2024 13:25
Hello Lance,

What compilers do with bit field is not covered by a standard and is implementation defined... so they do just about whatever they want.
BUT, something important is missing in you're code ! If you really want everything to be side by side, bit wise, you have to specify PACKED option on you're structs
search the web :
__attribute__((packed, aligned(X))) 
or
__PACKED__

This will force the compiler to 'pack' all the bits together not waisting anything : so you will have a stable size.

Note : positionning of the inside the struct is implementation defined ... so some compilers put them in on order, and others the other way around Wink
==> you're code won't be very portable



Thanks for your reply, Didier.

I am fine with padding. I am having issues with the way MSVC padding this one to unnecessary increase object size.

Also, for union, I expect objects taking same memory address. MSVC failed to deliver. I don't know what the standard says. But it's a tradition dated back to old C.

Are compiler free to reorder data members with the same access privileges? I will have to double check. Thanks again.
 
Read Message icon10.gif
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Math - GaussJordan function
Next Topic: Clang cannot find DLLs
Goto Forum:
  


Current Time: Thu Jul 03 17:23:40 CEST 2025

Total time taken to generate the page: 0.04007 seconds