From: John Love-Jensen <eljay@adobe.com>
To: "Humpolicek, Jiri - Acision" <jiri.humpolicek@acision.com>,
MSX to GCC <gcc-help@gcc.gnu.org>
Subject: Re: gcc warnings
Date: Wed, 17 Oct 2007 11:48:00 -0000 [thread overview]
Message-ID: <C33B5F2B.260FD%eljay@adobe.com> (raw)
In-Reply-To: <53248A54C3B3EC4EAAD993D10A6DD01203C5DAB7@cz-ex002.groupinfra.com>
Hi Jiri,
It's valid C code to assign from a variable of greater type to one of
smaller type.
I think that this is very unfortunate. I presume you do as well. Alas.
You can act upon it programmatically, in runtime, if you do something like:
#include "stdio.h"
unsigned char LongAsUnsignedChar(long c)
{
if(c > 255 || c < 0)
{
fprintf(stderr, "Error: %ld outside of 0,255 range\n", c);
}
return c;
}
int main()
{
long a = 10000;
unsigned char b = LongAsUnsignedChar(a);
printf("%d\n", b);
return b;
}
Alternatively, you can use a B&D language like Ada where such assignments
cannot happen silently and need explicit conversion.
HTH,
--Eljay
next prev parent reply other threads:[~2007-10-17 11:42 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-17 9:08 Humpolicek, Jiri - Acision
2007-10-17 11:48 ` John Love-Jensen [this message]
2007-10-17 11:49 ` Tom St Denis
2007-10-17 14:08 ` Humpolicek, Jiri - Acision
2007-10-17 13:28 ` Tim Prince
2007-10-17 14:28 ` Humpolicek, Jiri - Acision
2007-10-17 15:25 ` Andrew Haley
-- strict thread matches above, loose matches on Subject: below --
2008-08-12 15:36 kamelopardus
2008-08-12 15:48 ` Andrew Bell
2008-08-12 15:52 ` Joel Dice
2008-08-12 17:19 ` kamelopardus
2000-05-24 14:29 Zia Babar
2000-05-24 23:48 ` Martin v. Loewis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=C33B5F2B.260FD%eljay@adobe.com \
--to=eljay@adobe.com \
--cc=gcc-help@gcc.gnu.org \
--cc=jiri.humpolicek@acision.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).