__attribute__((__packed__)) on struct causes compilation error

__attribute__((__packed__)) on struct causes compilation error

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;
}

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

 

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

Judy

Leave a Comment

Please sign in to add a comment. Not a member? Join today