Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7944 Discussions

__attribute__((__packed__)) on struct causes compilation error

Tom_G_2
Beginner
545 Views

icpc --version
icpc (ICC) 13.0.1 20121010

with attribute packed turn on gets this error:

test.cpp(27): error: invalid type conversion: "char *" to "const char (&)[7]"
   set(ms.data);

without the attribute packed it compiles fine.

is this correct behavior?

#include <iostream>
#include <string.h>

char msg[90];

//struct __attribute__((__packed__)) MyStruct
struct MyStruct                            
{
 char data[7];
};

void set( const char (&str)[7] )
{
memcpy(msg,str,7);
}



int main()
{
 char str[7];
 str[0] = '1';
 str[1] = 0;

 MyStruct ms;

 set(ms.data);
 set(str);
 std::cout << msg << std::endl;
 return 0;
}

0 Kudos
1 Reply
Judith_W_Intel
Employee
545 Views

 

This looks like a bug. I have entered it into our internal bug tracking database as DPD200248124. Thanks for reporting it to us.

Judy

0 Kudos
Reply