Click here to Skip to main content
15,894,539 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow do you pass an int by reference to a function? Pin
Calin Negru11-Nov-23 3:57
Calin Negru11-Nov-23 3:57 
AnswerRe: How do you pass an int by reference to a function? Pin
Greg Utas11-Nov-23 4:19
professionalGreg Utas11-Nov-23 4:19 
GeneralRe: How do you pass an int by reference to a function? Pin
Richard MacCutchan11-Nov-23 4:49
mveRichard MacCutchan11-Nov-23 4:49 
GeneralRe: How do you pass an int by reference to a function? Pin
Greg Utas11-Nov-23 5:40
professionalGreg Utas11-Nov-23 5:40 
GeneralRe: How do you pass an int by reference to a function? Pin
Richard MacCutchan11-Nov-23 6:09
mveRichard MacCutchan11-Nov-23 6:09 
GeneralRe: How do you pass an int by reference to a function? Pin
honey the codewitch15-Nov-23 4:38
mvahoney the codewitch15-Nov-23 4:38 
GeneralRe: How do you pass an int by reference to a function? Pin
Greg Utas15-Nov-23 5:15
professionalGreg Utas15-Nov-23 5:15 
GeneralRe: How do you pass an int by reference to a function? Pin
Calin Negru11-Nov-23 5:31
Calin Negru11-Nov-23 5:31 
QuestionStruct initalization valid ? Pin
Maximilien7-Nov-23 8:08
Maximilien7-Nov-23 8:08 
AnswerRe: Struct initalization valid ? Pin
Mircea Neacsu7-Nov-23 8:17
Mircea Neacsu7-Nov-23 8:17 
GeneralRe: Struct initalization valid ? Pin
Maximilien7-Nov-23 8:39
Maximilien7-Nov-23 8:39 
AnswerRe: Struct initalization valid ? Pin
markkuk7-Nov-23 11:48
markkuk7-Nov-23 11:48 
GeneralRe: Struct initalization valid ? Pin
Maximilien8-Nov-23 2:32
Maximilien8-Nov-23 2:32 
GeneralRe: Struct initalization valid ? Pin
CPallini8-Nov-23 2:37
mveCPallini8-Nov-23 2:37 
AnswerRe: Struct initalization valid ? Pin
jschell8-Nov-23 6:01
jschell8-Nov-23 6:01 
AnswerRe: Struct initalization valid ? Pin
honey the codewitch8-Nov-23 10:03
mvahoney the codewitch8-Nov-23 10:03 
GeneralRe: Struct initalization valid ? Pin
k50548-Nov-23 12:31
mvek50548-Nov-23 12:31 
GeneralRe: Struct initalization valid ? Pin
honey the codewitch8-Nov-23 21:31
mvahoney the codewitch8-Nov-23 21:31 
GeneralRe: Struct initalization valid ? Pin
k50549-Nov-23 4:12
mvek50549-Nov-23 4:12 
GeneralRe: Struct initalization valid ? Pin
honey the codewitch9-Nov-23 4:51
mvahoney the codewitch9-Nov-23 4:51 
GeneralRe: Struct initalization valid ? Pin
k50549-Nov-23 6:49
mvek50549-Nov-23 6:49 
GeneralNot a question, just a lament about metaprogramming Pin
honey the codewitch28-Oct-23 22:19
mvahoney the codewitch28-Oct-23 22:19 
I love C++ because I can do things like this:

C++
// creates a BGRx pixel by making each channel 
// one quarter of the whole. Any remainder bits
// are added to the green channel. One channel
// is unused. Consumed by DirectX
template<size_t BitDepth>
using bgrx_pixel = gfx::pixel<
	gfx::channel_traits<gfx::channel_name::B,(BitDepth/4)>,
    gfx::channel_traits<gfx::channel_name::G,((BitDepth/4)+(BitDepth%4))>,
    gfx::channel_traits<gfx::channel_name::R,(BitDepth/4)>,
	gfx::channel_traits<gfx::channel_name::nop,(BitDepth/4),0,(1<<(BitDepth/4))-1,(1<<(BitDepth/4))-1>    
>;
using screen_t = uix::screen<gfx::bgrx_pixel<32>>;


Now, I've made pixels definable in terms of their memory footprint and what channels they expose, like R, G and B, or C, Y, and Mk or whatever. Above I'm defining a BGRx8888 pixel which DirectX uses for its surfaces. That's 3 8-bit channels with a fourth unused, blue first.

The above code is facilitated by this: gfx/include/gfx_pixel.hpp at master · codewitch-honey-crisis/gfx · GitHub[^]

That defines things like channel traits, and does all the necessary compile time computations to make it work.

The problem is this: It's write-only code, and there's no easy way to remedy it because meta-programming in C++17 and prior is very hackish. C++20 and beyond improve the situation a little, but the heavy reliance on The STL rather than language improvements to facilitate this leaves me wanting on little embedded platforms where the STL might not be complete or even available.

It's cool that with C++ you can even make facilities to enable code like the above, and it's the only language I know of that allows for it, but I really wish there was a cleaner way to do this stuff. Unsure | :~
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix

GeneralRe: Not a question, just a lament about metaprogramming Pin
jschell8-Nov-23 6:06
jschell8-Nov-23 6:06 
GeneralRe: Not a question, just a lament about metaprogramming Pin
honey the codewitch8-Nov-23 6:07
mvahoney the codewitch8-Nov-23 6:07 
GeneralRe: Not a question, just a lament about metaprogramming Pin
jschell9-Nov-23 7:03
jschell9-Nov-23 7:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.