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

enum warnings on Windows

erling_andersen
New Contributor I
363 Views

How do I get Intel 16 to generate warnings if I mix enum types.

# Begin


c:\Users\eda\mosekdbg>icl testenum.c
Intel(R) C++ Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0.2.180 Build 20160204
Copyright (C) 1985-2016 Intel Corporation.  All rights reserved.

testenum.c
Microsoft (R) Incremental Linker Version 11.00.50727.1
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:testenum.exe
testenum.obj

# End

clang says

eda@karise:~/mosekprj/dev$ clang-3.6 ~/testenum.c -o testenum

/home/eda/testenum.c:27:11: warning: implicit conversion from enumeration type 'anotherenum' to different enumeration type
      'someenum' [-Wenum-conversion]
   myfunc(mid);
   ~~~~~~ ^~~
1 warning generated.
eda@karise:~/mosekprj/dev$

 

And that is what I want. Can Intel C do that?

Here is the code I compile.

#include <stdio.h>

typedef enum
        {
          lower = 0,
          upper = 1     
        } someenum;

typedef enum
        {
          mid = 8
        } anotherenum;

 

void myfunc(someenum e)
{
   printf("enum test %d\n",(int) e); 
   if ( e>=lower )
        printf("e>=lower\n");
   else
     printf("e<lower\n");        
}

int main()
{
   myfunc(mid);
}

 

 

0 Kudos
3 Replies
Melanie_B_Intel
Employee
363 Views

You can see the warning like this:

  icc -c fu.c -diag-warning:188
fu.c(28): warning #188: enumerated type mixed with another type
     myfunc(mid);

I'll create a bug report about the missing Warning option:

-bash-4.2$ icc -c fu.c -Wenum-conversion
icc: command line warning #10006: ignoring unknown option '-Wenum-conversion'

The way I found the error number was to run the compiler with the -w3 option which prints all the available warnings and remarks. Then i used the "-diag-warning:188" option to print 188 as a warning

 icc -c fu.c -w3
fu.c(17): remark #1418: external function definition with no prior declaration
  void myfunc(someenum e)
       ^

fu.c(28): warning #188: enumerated type mixed with another type
     myfunc(mid);
            ^

fu.c(29): remark #1011: missing return statement at end of non-void function "main"
  }

 

0 Kudos
erling_andersen
New Contributor I
363 Views

On Windows it is /Qdiag-warning:188.  

0 Kudos
Kittur_G_Intel
Employee
363 Views

Thanks Melanie, as always.

@erling_andersen: Yes, it's /Qdiag-warning:188 on windows.

Kittur

0 Kudos
Reply