6 years, 1 month ago.

Structs causing C4017W compiler warning

I'm trying to create a struct called Color that contains several public variables, as well as some helpful constructors and methods. However, I'm getting inconsistent C4017W compiler warnings every time I create an instance of the struct. Here is a simplified test program that demonstrates the warning:

Test Program

#include "mbed.h"

//Color struct
struct Color {
    char red;
    char green;
    char blue;

    Color(char r, char g, char b) {
        red = r;
        green = g;
        blue = b;

int main()
    //Create a test Color and print it
    Color color(0xAD, 0xBE, 0xEF);
    printf("color: (0x%02X, 0x%02X, 0x%02X)\n", color.red, color.green, color.blue);

    //Don't exit main!

And here are the results of compiling it: /media/uploads/neilt6/c4017w.jpg

The inline constructor in the test program issues a C4017W every time. My main code, however, is using a separate implementation file for the constructors and methods, and it doesn't issue any warnings until I add a fourth variable for alpha. To make matters more interesting, if I move the constructor in the test program to a separate implementation file and add a fourth variable for alpha, the warning disappears! What the heck am I doing wrong here? Is this a compiler bug?

Be the first to answer this question.