News for hackers. Stuff that matters.
Re:Returning multiple values from functions in C++ by m_mueller on Sunday March 06, 2016 @09:09PM (#11236656)
Instead of markers, I like to use typedefs instead. Here's an example how this would look like in a HPC related program. Basically, if you know Fortran, you know where this is coming from.

    typedef const double * const __restrict__ IN;
    typedef double * const __restrict__ OUT;
    typedef const int INT_VALUE;
    typedef const double FP_VALUE;

    void diffuse_c(
        OUT runtime_total_s,
        OUT runtime_boundary_s,
        OUT thermal_energy_updated,
        IN thermal_energy,
        INT_VALUE nx,
        INT_VALUE ny,
        INT_VALUE nz
    );
Re:Returning multiple values from functions in C++ by Aeolos on Monday March 07, 2016 @02:13AM (#11237562)
I can't be the only one who finds "INT_VALUE" both superfluous and unnecessarily ugly?
Re:Returning multiple values from functions in C++ by m_mueller on Monday March 07, 2016 @02:18AM (#11237576)
You're right, I have been thinking about this naming as well. I think in this context, "INT_PARAM" would be better. I like to typedef it because this way it's easier to replace with a hardware specific integer type later on if I decide to do so. Anyways, the "VALUE" naming is coming from Fortran, which is by default pass-by-reference, so you use it to get pass-by-value.

Edit: Thinking about it some more, "INT_VALUE" still makes sense - it makes it clear that this specific symbol should be accessed as a value, not as a pointer. Doing this reminds me that I'm (probably) imposing more register pressure by passing by value. In general I'd probably pass a const int * const pointer here, but in this specific case I needed values because of some CUDA specific limitation.

Re:Returning multiple values from functions in C++ by Rexxar on Monday March 07, 2016 @02:56AM (#11237668)
> Doing this reminds me that I'm (probably) imposing more register pressure by passing by value.

Not for "int"s, I would be very surprised if sizeof(int*) < sizeof(int) on your system.

Re:Returning multiple values from functions in C++ by m_mueller on Monday March 07, 2016 @03:41AM (#11237803)
Good point, that was a bit of a brainfart of mine.