D
david
I've noticed that the following compiles (as C) under both VS8 and gcc
with no warnings, even though there's a possibility of data truncation
from enum to unsigned char. It does generate a warning under VS6,
however. Under VS8, I enabled run-time checks, including /RTCc
(smaller type check), but still no warning. The only way I can get a
warning under VS8 is if I configure it to compile as C++.
Two questions:
(1) why doesn't /RTCc pick up the data truncation (enum to unsigned
char)?
(2) is there any way to configure VS8 (aside from compiling as C++)
that will generate a warning?
Here's the code:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
void foo(unsigned char result);
void bar(void);
typedef enum {
OK = 0,
NOT_OK = 1,
NO_STATUS = 0xffff
} STATUS;
int main(int argc, char* argv[])
{
bar();
printf("%d %s", argc, argv[0]);
return 0;
}
void bar(void)
{
STATUS status = OK;
foo(status);
}
void foo(unsigned char result)
{
result++;
return;
}
with no warnings, even though there's a possibility of data truncation
from enum to unsigned char. It does generate a warning under VS6,
however. Under VS8, I enabled run-time checks, including /RTCc
(smaller type check), but still no warning. The only way I can get a
warning under VS8 is if I configure it to compile as C++.
Two questions:
(1) why doesn't /RTCc pick up the data truncation (enum to unsigned
char)?
(2) is there any way to configure VS8 (aside from compiling as C++)
that will generate a warning?
Here's the code:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
void foo(unsigned char result);
void bar(void);
typedef enum {
OK = 0,
NOT_OK = 1,
NO_STATUS = 0xffff
} STATUS;
int main(int argc, char* argv[])
{
bar();
printf("%d %s", argc, argv[0]);
return 0;
}
void bar(void)
{
STATUS status = OK;
foo(status);
}
void foo(unsigned char result)
{
result++;
return;
}