473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

no warning for data truncation?

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;
}
Oct 23 '08 #1
2 2582
david said:
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.
That's not a syntax error or a constraint violation, so implementations are
not required to diagnose it. They may *choose* to diagnose it.

I get a warning from gcc:

foo.c:26: warning: passing arg 1 of `foo' with different width due to
prototype
(2) is there any way to configure VS8 (aside from compiling as C++)
that will generate a warning?
Firstly, make sure /W4 and /Za are switched on. Failing that, I suggest you
take this up in a Windows group, comp.os.ms-windows.programmer.win32 being
the obvious choice to start off with, since that group is more likely to
have a good solid core of VS8 experts than is comp.lang.c. But you may
find that they, in turn, refer you to a Microsoft-hosted group.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Oct 23 '08 #2
On Oct 23, 4:40*pm, Richard Heathfield <r...@see.sig.invalidwrote:
>
Firstly, make sure /W4 and /Za are switched on. Failing that, I suggest you
Thanks for the tip. Using /W4 and /Za caused the following warning:

warning C4244: 'function' : conversion from 'STATUS' to 'unsigned
char', possible loss of data

Which is what I was hoping to see.

Cheers.
Oct 24 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: dis | last post by:
I've been going through my code and clearing away some of the compiler warnings that i'm generating and i've come across areas where i cast pointers to integer values. The Visual Studio compiler...
10
by: joel.brewster | last post by:
We have a VB6 application using ADO version 2.5 and I am receiving a " CLI0109E String data right truncation. SQLSTATE=22001" error when I execute the rs.UpdateBatch method. I have determined...
2
by: Magix | last post by:
Hi, I have following code. char buffer; void string_addchar(char *sourc, char ch) { int length; length=strlen(sourc);
9
by: Sean | last post by:
I am using a datagrid to display some data. I notice when I click in a cell where the data is longer than the cell width, it truncates the end of the data off. For example: The data is: This...
24
by: asdf | last post by:
I got a warning from the following statement: fprintf(point_file, "CONTOUR\nCLOSE\n%d\n", curve.size()); warning: format '%d' expects type 'int', but argument 3 has type 'size_t' should I...
2
by: BSeab1024SE | last post by:
In MS Visual C++ some code I wrote generated the warning "conversion from 'int' to 'const float', possible loss of data." In the process of trying to determine if I could rewrite the code to...
12
by: Juan Carlos Espinoza | last post by:
i have a problem com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data truncated for column 'FGiroNPagDol' at row 1 at...
21
by: Roman Mashak | last post by:
Hello, given a simple code: #include <math.h> long hyp(long height, long base) { return sqrt(height * height + base * base); }
2
by: Pranav | last post by:
template <class X> class Node{ : : }; template <class X> class Link { :
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.