Skip to content

Proposal: Make can.h Compatible With Other Compilers #122

@ptoshkov

Description

@ptoshkov

Hello,

Thanks for the great project.

I have unit tests for my project which run on Windows and are compiled with MSVC. The unit tests include can.h.

There is some GCC-specific code in can.h and it doesn't compile directly on MSVC:

struct can_frame {
    canid_t can_id;  /* 32 bit CAN_ID + EFF/RTR/ERR flags */
    __u8    can_dlc; /* frame payload length in byte (0 .. CAN_MAX_DLEN) */
    __u8    data[CAN_MAX_DLEN] __attribute__((aligned(8)));
};

Would it be possible to isolate the GCC-specific __attribute__ so that the header can be included in an MSVC project?

Something like

struct can_frame {
    canid_t can_id;  /* 32 bit CAN_ID + EFF/RTR/ERR flags */
    __u8    can_dlc; /* frame payload length in byte (0 .. CAN_MAX_DLEN) */
    __u8    data[CAN_MAX_DLEN]
#if defined(__GNUC__)
__attribute__((aligned(8)))
#endif
;
};

or

#if defined(__GNUC__)
#define ALIGNED(x) __attribute__((aligned(x)))
#else
#if defined(_MSC_VER)
#define ALIGNED(x) __declspec(align(x))
#endif
#endif

struct can_frame {
    canid_t can_id;  /* 32 bit CAN_ID + EFF/RTR/ERR flags */
    __u8    can_dlc; /* frame payload length in byte (0 .. CAN_MAX_DLEN) */
    __u8    data[CAN_MAX_DLEN] ALIGNED(8);
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions