| delorie.com/archives/browse.cgi | search |
| Date: | Wed, 20 Jun 2001 21:03:47 +0300 |
| From: | "Eli Zaretskii" <eliz AT is DOT elta DOT co DOT il> |
| Sender: | halo1 AT zahav DOT net DOT il |
| To: | Martin Str|mberg <ams AT ludd DOT luth DOT se> |
| Message-Id: | <4949-Wed20Jun2001210347+0300-eliz@is.elta.co.il> |
| X-Mailer: | Emacs 20.6 (via feedmail 8.3.emacs20_6 I) and Blat ver 1.8.9 |
| CC: | djgpp-workers AT delorie DOT com |
| In-reply-to: | <200106201703.TAA22756@father.ludd.luth.se> (message from Martin |
| Str|mberg on Wed, 20 Jun 2001 19:03:03 +0200 (MET DST)) | |
| Subject: | Re: Casting left side to unsigned or right side to signed? |
| References: | <200106201703 DOT TAA22756 AT father DOT ludd DOT luth DOT se> |
| Reply-To: | djgpp-workers AT delorie DOT com |
| Errors-To: | nobody AT delorie DOT com |
| X-Mailing-List: | djgpp-workers AT delorie DOT com |
| X-Unsubscribes-To: | listserv AT delorie DOT com |
> From: Martin Str|mberg <ams AT ludd DOT luth DOT se>
> Date: Wed, 20 Jun 2001 19:03:03 +0200 (MET DST)
>
> else if (header[0] == 0x5a4d) /* "MZ" */
> {
> char go32stub[9];
> - unsigned long coff_start = (unsigned long)header[2]*512L;
> - unsigned long exe_start;
> - unsigned long real_exe_start;
> + off_t coff_start = header[2]*512L;
> + off_t exe_start;
> + off_t real_exe_start;
> type.exec_format = _V2_EXEC_FORMAT_EXE;
>
> Should I keep the cast here too?
I'm paranoiac about promotion from unsigned short to signed int (off_t
is signed), so I would keep the cast. But perhaps people who are more
sure in what C mandates than I am will have different advice ;-)
> 2. If we decided to do the cast (theoretically speaking) which way is
> best to cast? signed -> unsigned or unsigned -> signed?
If you know that the value is non-negative, then signed->unsigned is
safer.
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |