# Nvc++ / g++ bitfield incompatibility

**URL:** <https://forums.developer.nvidia.com/t/nvc-g-bitfield-incompatibility/308099>\
**Category:** nvc, nvc++ and nvfortran\
**Created:** [September 27, 2024, 1:49pm UTC](https://forums.developer.nvidia.com/t/nvc-g-bitfield-incompatibility/308099 "2024-09-27T13:49:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josh\_Perske](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/josh_perske/32/143066_2.png) [@Josh\_Perske](https://forums.developer.nvidia.com/u/Josh_Perske)\
**Post date:** [September 27, 2024, 1:49pm UTC](https://forums.developer.nvidia.com/t/nvc-g-bitfield-incompatibility/308099/1 "2024-09-27T13:49:02Z")

</div>

Hi everyone,

I’m observing a strange behaviour when I try to call a function located in a shared library compiled with g++ from another program compiled with nvc++. The parameters passed to a called function seem to get corrupted during the function call.

Here you can find a minimal example showing off this behaviour. The example code uses **g++-9** to compile a shared library and **nvc++** to compile the main.

[test.zip](https://forums.developer.nvidia.com/uploads/short-url/oJ7mJEC5MP3DmMLWFZIpvtft2NB.zip) (2.4 KB)

**compile commands**

```auto
mkdir build
cd build
cmake ..
make -j
./src/main

```

The expected output is `###### pid 42 kid 0` but I actually get `###### pid <some_random_number> kid 42` with changing results on every run.

Here is a short explanation of what the code does:

The class _myclass_ is compiled with g++ to create a shared library providing the static method _myclass::foo_.

**myclass.hpp**

```auto
[...]
class myclass {
    public:
    struct {
        uint64_t a : 24;
        uint64_t b : 32;
        uint64_t c : 8;
    } fields;
    static myclass foo(uint8_t pid, uint32_t key_id);
};

```

**myclass.cpp**

```auto
[...]
myclass myclass::foo(uint8_t pid, uint32_t key_id)
{
    std::cout << "###### pid " << int(pid) << " kid " << int(key_id) << std::endl;
    myclass result;
    return result;
}

```

The _main_ function is compiled with **nvc++** and calls _foo_.

**main.cpp**

```auto
int main(int argc, char* argv[]) {
    auto var = 42;
    auto tmp = myclass::foo(var, 0);
    return 0;
}

```

As far as I can tell, the problem occurs only if the static function is not void and is located behind a bitfield with specific bit widths. When I compile both, the library and the main, with the same compiler (no matter if g++ or nvc++) everything works as expected. Unfortunately for the project in which I ran into those problems, we are not able change the library toolchain to nvc++ due to other requirements.

Is anyone able to reproduce this behaviour with the given example project?  
Are there known bugs that could be related to this?  
Or am I just missing some obvious undefined behaviour causing stuff here?

Thank you and best regards  
Josh

Edit:  
nvc++ version : 23.1-0  
g++ version : 9.4.0

---

<div class="post-metadata">

**Author:** ![MatColgrove](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/matcolgrove/32/14047_2.png) [@MatColgrove](https://forums.developer.nvidia.com/u/MatColgrove)\
**Post date:** [September 27, 2024, 4:32pm UTC](https://forums.developer.nvidia.com/t/nvc-g-bitfield-incompatibility/308099/2 "2024-09-27T16:32:39Z")

</div>

Thanks for the report Josh. I’ve filed an issue report, TPR #36572, and sent it to engineering for investigation.

I tired the code with multiple versions of g++ and nvc++, as well as several systems. The compiler version don’t seem to matter, but the error does only occur on x86\_64, it seems to get correct results on ARM.

---

<div class="post-metadata">

**Author:** ![Josh\_Perske](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/josh_perske/32/143066_2.png) [@Josh\_Perske](https://forums.developer.nvidia.com/u/Josh_Perske)\
**Post date:** [September 30, 2024, 7:21am UTC](https://forums.developer.nvidia.com/t/nvc-g-bitfield-incompatibility/308099/3 "2024-09-30T07:21:23Z")

</div>

Hi Mat, thank you for your effort. I forgot to mention that I ran the program on x86\_64, so that fits your tests. I will try to work around this issue for now and I’m looking forward to the results of the engineering.

---

<div class="post-metadata">

**Author:** ![Josh\_Perske](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/josh_perske/32/143066_2.png) [@Josh\_Perske](https://forums.developer.nvidia.com/u/Josh_Perske)\
**Post date:** [January 27, 2025, 3:05pm UTC](https://forums.developer.nvidia.com/t/nvc-g-bitfield-incompatibility/308099/4 "2025-01-27T15:05:20Z")

</div>

Hi Mat,  
is there an update on this bug and could you give me a status update on your issue report? In another project we ran into a similar problem when linking non-nvc++ libraries against nvc+±compiled binaries.

Thank you and best regards  
Josh

---

<div class="post-metadata">

**Author:** ![MatColgrove](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/matcolgrove/32/14047_2.png) [@MatColgrove](https://forums.developer.nvidia.com/u/MatColgrove)\
**Post date:** [January 27, 2025, 3:30pm UTC](https://forums.developer.nvidia.com/t/nvc-g-bitfield-incompatibility/308099/5 "2025-01-27T15:30:43Z")

</div>

Hi Josh,

Looks like a fix made it into [25.1](https://developer.nvidia.com/hpc-sdk-downloads) which was just released last week.

-Mat

---

<div class="post-metadata">

**Author:** ![Josh\_Perske](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/josh_perske/32/143066_2.png) [@Josh\_Perske](https://forums.developer.nvidia.com/u/Josh_Perske)\
**Post date:** [January 27, 2025, 3:50pm UTC](https://forums.developer.nvidia.com/t/nvc-g-bitfield-incompatibility/308099/6 "2025-01-27T15:50:25Z")

</div>

Hi Mat, thanks for the fast reply. What a timing, I will test the new version asap. Thank you for your support :)

---

<div class="post-metadata">

**Author:** ![Josh\_Perske](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/josh_perske/32/143066_2.png) [@Josh\_Perske](https://forums.developer.nvidia.com/u/Josh_Perske)\
**Post date:** [January 28, 2025, 1:41pm UTC](https://forums.developer.nvidia.com/t/nvc-g-bitfield-incompatibility/308099/7 "2025-01-28T13:41:11Z")

</div>

I just tested two projects with the new HPC-SDK and I was unable to reproduce the errors. Great. For the record, we had the same problems linking Qt5 qwt libraries with nvc++, now it works without any issues.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/system/32/68080_2.png) [@system](https://forums.developer.nvidia.com/u/system)\
**Post date:** [February 11, 2025, 1:41pm UTC](https://forums.developer.nvidia.com/t/nvc-g-bitfield-incompatibility/308099/8 "2025-02-11T13:41:22Z")

</div>

Closed on February 11, 2025, 1:41pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
