dan@rna.UUCP (Dan Ts'o) (08/21/87)
While converting a large C program from small model to large model using MSC 4.0, I encountered a problem not found on all other (UNIX) C compilers. It went something like this: char *s0, *s1, *buf0, *buf1; buf0 = malloc(512); /* Get two char buffers */ buf1 = malloc(512); gets(buf0); /* Fill with a line of text */ strcpy(buf1, buf0); /* Copy to second buffer */ /* Some kind of lexical analysis, moving s0 to somewhere within buf0 */ for (s0 = buf0; *s0 && *s0 != '/'; s0++); if (*s0 == '/') /*WARNING*/ s1 = buf1 + (s0 - buf0);/* I want s3 to point in the same respective position in buf1 */ The last line provoked 2 warnings from MSC 4.0, both something like: Warning: conversion of far pointer to int. The binary result did not run. Fare enough, so I explicitly casted an (int): s1 = buf1 + (int)(s0 - buf0); With this code, I got one such warning and the code still didn't run. I didn't try casting to (long), figuring that you can't have objects greater than 64Kb anyways, although (long) might have made sense. Instead I settled for this, which removed the warning and worked: int n; ... n = s0 - buf0; s1 = &buf1[n]; I believe, int n; ... n = s0 - buf0; s1 = buf1 + n; also works. Can anyone tell me the big difference between casting (int) which didn't work and assigning explicitly to an int, which did work ? Thanks. Cheers, Dan Ts'o Dept. Neurobiology 212-570-7671 Rockefeller Univ. ...cmcl2!rna!dan 1230 York Ave. rna!dan@nyu.arpa NY, NY 10021
darrylo@hpsrla.HP.COM (Darryl Okahata) (08/24/87)
In comp.sys.ibm.pc, dan@rna.UUCP (Dan Ts'o) writes: > While converting a large C program from small model to large model > using MSC 4.0, I encountered a problem not found on all other (UNIX) > C compilers. It went something like this: [ ... ] > Thanks. > Cheers, > Dan Ts'o > Dept. Neurobiology 212-570-7671 > Rockefeller Univ. ...cmcl2!rna!dan > 1230 York Ave. rna!dan@nyu.arpa > NY, NY 10021 > ---------- I can't duplicate your problem. What compilation flags are you using? -- Darryl Okahata UUCP: { hplabs!hpcea, hpfcla }!hpsrla!darrylo CompuServe: 75206,3074 Disclaimer: the above is the author's personal opinion and is not the opinion or policy of his employer or of the little green men that have been following him all day.