* Bug in CC? (OSF1 4.0)
@ 1997-10-20 4:00 Akim Demaille
1997-10-20 4:00 ` Rich Peterson
1997-10-21 4:00 ` Akim Demaille
0 siblings, 2 replies; 3+ messages in thread
From: Akim Demaille @ 1997-10-20 4:00 UTC (permalink / raw)
--Multipart_Mon_Oct_20_10:52:55_1997-1
Content-Type: text/plain; charset=US-ASCII
Hi !
I maintain a2ps, a PostScript generating package. It is quite
portable, but I still have problems with... OSF1 4.0.
One of the problems I encounter is a weird behavior of native
cc. On the attached file (cc -E of the file giving problems), I get
the following problems:
$ cc foo.c -c
cc: Error: foo.c, line 534: In this declaration, the type of
"ds_strccat" is not compatible with the type of a previous declaration
of "ds_strccat" at line number 339 in file foo.c.
ds_strccat (struct dstring *s, char c)
^
cc: Error: foo.c, line 624: In this declaration, the type of
"ds_getdelim" is not compatible with the type of a previous
declaration of "ds_getdelim" at line number 353 in file foo.c.
char *
-----^
$ uname -a
OSF1 elecsrv.enst.fr V4.0 464 alpha
The line 534 is
void /* 533 */
ds_strccat (struct dstring *s, char c)
and 339 is
void ds_strccat ();
Can somebody explain me what is going on? The other is
identical. I have no problem with the other functions!
--Multipart_Mon_Oct_20_10:52:55_1997-1
Content-Type: application/octet-stream
Content-Disposition: attachment; filename="foo.c"
Content-Transfer-Encoding: 8bit
typedef unsigned long size_t;
typedef long fpos_t;
typedef struct {
int _cnt;
unsigned int _flag2;
unsigned char *_ptr;
unsigned char *_base;
int _bufsiz;
short _flag;
short _file;
char *__newbase;
void *_lock;
unsigned char *_bufendp;
} FILE;
extern FILE _iob[];
extern int fread();
extern int fwrite();
extern int _flsbuf ();
extern int _filbuf ();
extern int ferror ();
extern int feof ();
extern void clearerr ();
extern int putchar ();
extern int getchar ();
extern int putc ();
extern int getc ();
extern int remove ();
extern int rename ();
extern FILE *tmpfile ();
extern char *tmpnam ();
extern int fclose ();
extern int fflush ();
extern FILE *fopen ();
extern FILE *freopen ();
extern void setbuf ();
extern int setvbuf ();
extern int fprintf ();
extern int fscanf ();
extern int printf ();
extern int scanf ();
extern int sprintf ();
extern int sscanf ();
typedef struct {
char **_a0;
int _offset;
} va_list;
extern int vfprintf ();
extern int vprintf ();
extern int vsprintf ();
extern int fgetc ();
extern char *fgets ();
extern int fputc ();
extern int fputs ();
extern char *gets ();
extern int puts ();
extern int ungetc ();
extern int fgetpos ();
extern int fseek ();
extern int fsetpos ();
extern long ftell ();
extern void rewind ();
extern void perror ();
typedef signed long ptrdiff_t;
typedef unsigned int wchar_t;
typedef unsigned int wctype_t;
typedef int time_t;
typedef int clock_t;
typedef long ssize_t;
typedef unsigned char uchar_t;
typedef unsigned short ushort_t;
typedef unsigned int uint_t;
typedef unsigned long ulong_t;
typedef volatile unsigned char vuchar_t;
typedef volatile unsigned short vushort_t;
typedef volatile unsigned int vuint_t;
typedef volatile unsigned long vulong_t;
typedef struct { long r[1]; } *physadr_t;
typedef struct label_t {
long val[10];
} label_t;
typedef int level_t;
typedef int daddr_t;
typedef char * caddr_t;
typedef long * qaddr_t;
typedef char * addr_t;
typedef uint_t ino_t;
typedef short cnt_t;
typedef int dev_t;
typedef int chan_t;
typedef long off_t;
typedef unsigned long rlim_t;
typedef int paddr_t;
typedef ushort_t nlink_t;
typedef int key_t;
typedef uint_t mode_t;
typedef uint_t uid_t;
typedef uint_t gid_t;
typedef void * mid_t;
typedef int pid_t;
typedef char slab_t[12];
typedef ulong_t shmatt_t;
typedef ulong_t msgqnum_t;
typedef ulong_t msglen_t;
typedef unsigned int wint_t;
typedef unsigned long sigset_t;
typedef struct __pthread_attr_t {
long __valid;
char* __name;
unsigned long __arg;
unsigned long __reserved[19];
} pthread_attr_t;
typedef struct __pthread_mutexattr_t {
long __valid;
unsigned long __reserved[15];
} pthread_mutexattr_t;
typedef struct __pthread_condattr_t {
long __valid;
unsigned long __reserved[13];
} pthread_condattr_t;
typedef struct __pthread_t {
void* __reserved1;
void* __reserved2;
unsigned short __size;
unsigned char __reserved3[2];
unsigned char __reserved4[4];
unsigned long __sequence;
unsigned long __reserved5[2];
void* __per_kt_area;
void* __stack_base;
void* __stack_reserve;
void* __stack_yellow;
void* __stack_guard;
unsigned long __stack_size;
void** __tsd_values;
unsigned long __tsd_count;
unsigned int __reserved6;
unsigned int __reserved7;
unsigned int __thread_flags;
} *pthread_t;
typedef volatile struct __pthread_mutex_t {
unsigned int __lock;
unsigned int __valid;
char* __name;
unsigned int __arg;
unsigned int __depth;
unsigned long __sequence;
unsigned long __owner;
void* __block;
} pthread_mutex_t;
typedef volatile struct __pthread_cond_t {
unsigned int __state;
unsigned int __valid;
char* __name;
unsigned int __arg;
unsigned long __sequence;
void* __block;
} pthread_cond_t;
typedef unsigned int pthread_key_t;
typedef volatile struct __pthread_once_t {
long __state;
long __reserved[10];
} pthread_once_t;
typedef long timer_t;
typedef void (*sig_t) ();
typedef pid_t id_t;
typedef unsigned int useconds_t;
typedef uint_t major_t;
typedef uint_t minor_t;
typedef uint_t devs_t;
typedef uint_t unit_t;
typedef unsigned long vm_offset_t;
typedef unsigned long vm_size_t;
typedef uchar_t uchar;
typedef ushort_t ushort;
typedef uint_t uint;
typedef ulong_t ulong;
typedef physadr_t physadr;
typedef uchar_t u_char;
typedef ushort_t u_short;
typedef uint_t u_int;
typedef ulong_t u_long;
typedef vuchar_t vu_char;
typedef vushort_t vu_short;
typedef vuint_t vu_int;
typedef vulong_t vu_long;
typedef struct _quad { int val[2]; } quad;
typedef long swblk_t;
typedef u_long fixpt_t;
typedef int fd_mask;
typedef struct fd_set {
fd_mask fds_bits[(((4096)+(((sizeof(fd_mask) * 8))-1))/((sizeof(fd_mask) * 8)))];
} fd_set;
extern void bzero ();
struct timeval;
int select ();
typedef unsigned char sa_family_t;
typedef unsigned int in_addr_t;
typedef unsigned short in_port_t;
extern int fileno ();
extern FILE *fdopen ();
extern char *cuserid ();
extern char *optarg;
extern int optind;
extern int opterr;
extern int optopt;
struct option
{
char *name;
int has_arg;
int *flag;
int val;
};
extern int rpl_getopt ();
extern int getopt_long ();
extern int getopt_long_only ();
extern int _getopt_internal ();
extern char *ctermid ();
extern int getw ();
extern int pclose ();
extern int putw ();
extern FILE *popen ();
extern char *tempnam ();
extern void setbuffer ();
extern void setlinebuf ();
struct lconv {
char *decimal_point;
char *thousands_sep;
char *grouping;
char *int_curr_symbol;
char *currency_symbol;
char *mon_decimal_point;
char *mon_thousands_sep;
char *mon_grouping;
char *positive_sign;
char *negative_sign;
char int_frac_digits;
char frac_digits;
char p_cs_precedes;
char p_sep_by_space;
char n_cs_precedes;
char n_sep_by_space;
char p_sign_posn;
char n_sign_posn;
char *left_parenthesis;
char *right_parenthesis;
};
struct lconv *localeconv ();
char *setlocale ();
struct _msg_ent
{
const char *_msg;
int _msg_number;
};
extern char *gettext ();
extern char *gettext__ ();
extern char *dgettext ();
extern char *dgettext__ ()
;
extern char *dcgettext ()
;
extern char *dcgettext__ ()
;
extern char *textdomain ();
extern char *textdomain__ ();
extern char *bindtextdomain ()
;
extern char *bindtextdomain__ ()
;
extern char *memchr();
extern char *memcpy();
extern char *memset();
extern int strcspn();
extern int strlen();
extern int strspn();
extern void *memmove ();
extern char *strcpy ();
extern char *strncpy ();
extern char *strcat ();
extern char *strncat ();
extern int memcmp ();
extern int strcmp ();
extern int strcoll ();
extern int strncmp ();
extern size_t strxfrm ();
extern char *strchr ();
extern char *strpbrk ();
extern char *strrchr ();
extern char *strstr ();
extern char *strtok ();
extern char *strerror ();
extern char *memccpy();
extern void swab ();
extern char *strdup ();
extern int bcmp ();
extern void bcopy ();
extern void bzero ();
extern int ffs ();
extern char *index ();
extern char *rindex ();
extern int strcasecmp ();
extern int strncasecmp ();
extern char * sidestep_basename_declaration ();
extern char * sidestep_dirname_declaration ();
extern char *strchr ();
extern char *strrchr ();
extern char *strndup ();
extern char *basename ();
extern char *dirname ();
extern int ds_exit_error;
enum ds_growth {
ds_steady,
ds_linear,
ds_geometrical
};
struct dstring {
size_t len;
enum ds_growth growth;
size_t increment;
size_t size;
char *content;
} ;
struct dstring *
ds_new ()
;
void ds_erase ();
void ds_report ();
void ds_resize ();
void ds_grow ();
int ds_is_full ();
void ds_strcat ();
void ds_strncat ();
void ds_strccat ();
void ds_vsprintf ()
;
void ds_cat_vsprintf ()
;
void ds_unsafe_vsprintf ()
;
void ds_unsafe_cat_vsprintf ()
;
void ds_sprintf ();
void ds_unsafe_sprintf ();
void ds_cat_sprintf ();
void ds_unsafe_cat_sprintf ();
char *ds_getline ();
char *ds_getdelim ();
void error ();
void error_at_line ();
extern void (*error_print_progname) ();
extern unsigned int error_message_count;
extern int error_one_per_line;
typedef struct div_t {
int quot;
int rem; } div_t;
typedef struct ldiv_t {
long int quot;
long int rem; } ldiv_t;
extern int __getmbcurmax ();
extern int mblen ();
extern size_t mbstowcs ();
extern int mbtowc ();
extern size_t wcstombs ();
extern int wctomb ();
extern int rpmatch ();
extern void *valloc ();
extern double atof ();
extern int atoi ();
extern long int atol ();
extern double strtod ();
extern long int strtol ();
extern unsigned long int strtoul ();
extern int rand ();
extern void srand ();
extern void *calloc ();
extern void free ();
extern void *malloc ();
extern void *realloc ();
extern long a64l ();
extern char * l64a ();
extern int ttyslot ();
extern char *ptsname ();
extern void abort ();
extern int atexit ();
extern void exit ();
extern char *getenv ();
extern int system ();
extern void *bsearch ();
extern void qsort ();
extern int abs ();
extern struct div_t div ();
extern long int labs ();
extern struct ldiv_t ldiv ();
extern int rand_r ();
extern double drand48 ();
extern double erand48 ();
extern long jrand48 ();
extern void lcong48 ();
extern long lrand48 ();
extern long mrand48 ();
extern long nrand48 ();
extern unsigned short *seed48 ();
extern void srand48 ();
extern int putenv ();
extern void setkey ();
extern char *initstate ();
extern char *setstate ();
extern int grantpt ();
extern int getsubopt ();
extern int random ();
extern int srandom ();
extern char *realpath ();
extern int unlockpt ();
extern int clearenv ();
extern char *getpass ();
extern char *mktemp ();
extern int mkstemp ();
char *ecvt ();
char *fcvt ();
char *gcvt ();
char * xmalloc ();
char * xcalloc ();
char * xrealloc ();
char *xstrdup ();
int printflen ();
int vprintflen ();
int ds_exit_error = (1);
struct dstring *
ds_new (size_t size,
enum ds_growth growth, size_t increment)
{
struct dstring * res;
if (size < 0)
error (ds_exit_error, 0, "invalid size for dynamic string: %d",
size);
if ((increment < 0)
|| (increment == 0 && growth != ds_steady))
error (ds_exit_error, 0, "invalid increment for dynamic string: %d",
increment);
res = ((struct dstring *) xmalloc (sizeof (struct dstring) * (1)));
res->len = 0;
res->size = size;
res->growth = growth;
res->increment = increment;
res->content = ((char *) xmalloc (sizeof (char) * (size)));
res->content[0] = '\0';
return res;
}
void
ds_erase (struct dstring *string)
{
free (string->content);
free (string);
}
void
ds_report (struct dstring * str, FILE * stream)
{
char * cp = 0L;
fprintf (stream, dcgettext (0L, "Dynamic string:\n", 5));
fprintf (stream, dcgettext (0L, "\tload: %d/%d (%2.1f%%)\n", 5),
str->len, str->size, 100.0 * str->len / str->size);
switch (str->growth) {
case ds_steady:
cp = dcgettext (0L, "steady", 5);
break;
case ds_linear:
cp = dcgettext (0L, "linear", 5);
break;
case ds_geometrical:
cp = dcgettext (0L, "geometrical", 5);
break;
default:
error (ds_exit_error, 0, "invalid growth type for dstring");
}
fprintf (stream, dcgettext (0L, "\tgrowth: %s, increment: %d\n", 5),
cp, str->increment);
}
void
ds_resize (struct dstring *string, size_t size)
{
if (string->len + 1 < size) {
string->size = size;
string->content = ((char *) xrealloc ((string->content), sizeof (char) * (size)));
}
}
void
ds_grow (struct dstring *string)
{
switch (string->growth) {
case ds_steady:
return;
case ds_linear:
string->size += string->increment;
break;
case ds_geometrical:
string->size *= string->increment;
break;
}
string->content = ((char *) xrealloc ((string->content), sizeof (char) * (string->size)));
}
\f
int
ds_is_full (struct dstring *str)
{
return (str->len + 1 >= str->size);
}
\f
void
ds_strcat (struct dstring *s, char *t)
{
size_t len = s->len;
s->len += strlen (t);
if (ds_is_full (s))
ds_grow (s);
strcpy (s->content + len, t);
}
void
ds_strncat (struct dstring *s, char *t, int n)
{
size_t len = s->len;
s->len += n;
if (ds_is_full (s))
ds_grow (s);
strncpy (s->content + len, t, n);
s->content[s->len] = '\0';
}
void
ds_strccat (struct dstring *s, char c)
{
if (s->len + 2 >= s->size)
ds_grow (s);
s->content [s->len++] = c;
s->content [s->len] = '\0';
}
\f
void
ds_vsprintf (struct dstring * ds, const char *format, va_list args)
{
int len;
len = vprintflen (format, args);
ds_resize (ds, len);
vsprintf (ds->content, format, args);
ds->len = strlen (ds->content);
}
void
ds_sprintf (ds, format, va_alist)
struct dstring * ds;
char * format;
long va_alist;
{
va_list args;
__builtin_va_start(args, va_alist, 0);
ds_vsprintf (ds,
format, args);
;
}
void
ds_cat_vsprintf (struct dstring * ds, const char *format, va_list args)
{
int len;
len = ds->len + vprintflen (format, args);
ds_resize (ds, len);
vsprintf (ds->content + ds->len, format, args);
ds->len += strlen (ds->content + ds->len);
}
void
ds_cat_sprintf (ds, format, va_alist)
struct dstring * ds;
char * format;
long va_alist;
{
va_list args;
__builtin_va_start(args, va_alist, 0);
ds_cat_vsprintf (ds,
format, args);
;
}
\f
void
ds_unsafe_vsprintf (struct dstring * ds, const char *format, va_list args)
{
vsprintf (ds->content, format, args);
ds->len = strlen (ds->content);
}
void
ds_unsafe_sprintf (ds, format, va_alist)
struct dstring * ds;
char * format;
long va_alist;
{
va_list args;
__builtin_va_start(args, va_alist, 0);
ds_unsafe_vsprintf (ds,
format, args);
;
}
void
ds_unsafe_cat_vsprintf (struct dstring * ds, const char *format, va_list args)
{
if (ds->size < ds->len + 1024)
ds_grow (ds);
vsprintf (ds->content + ds->len, format, args);
ds->len += strlen (ds->content + ds->len);
}
void
ds_unsafe_cat_sprintf (ds, format, va_alist)
struct dstring * ds;
char * format;
long va_alist;
{
va_list args;
__builtin_va_start(args, va_alist, 0);
ds_unsafe_cat_vsprintf (ds,
format, args);
;
}
\f
char *
ds_getdelim (struct dstring *s, char eos, FILE *f)
{
int insize;
int strsize;
int next_ch;
insize = 0;
strsize = s->len;
next_ch = (--(f)->_cnt < 0 ? _filbuf(f) : (int) *(f)->_ptr++);
while (next_ch != eos && next_ch != (-1))
{
if (insize >= strsize - 1)
{
ds_grow (s);
strsize = s->len;
}
s->content[insize++] = next_ch;
next_ch = (--(f)->_cnt < 0 ? _filbuf(f) : (int) *(f)->_ptr++);
}
s->content[insize++] = '\0';
if (insize == 1 && next_ch == (-1))
return 0L;
else
return s->content;
}
char *
ds_getline (struct dstring *s, FILE *f)
{
return ds_getdelim (s, '\n', f);
}
--Multipart_Mon_Oct_20_10:52:55_1997-1
Content-Type: text/plain; charset=US-ASCII
If somebody could also try whether there are things I should
know to ensure portability, please don't hesitate to fetch a2ps :)
ftp://ftp.enst.fr/outgoing/demaille/a2ps-4.9.8a.tar.gz
Note that due to a libtool bug, you need to configure with --disable-shared.
http://www-inf.enst.fr/~demaille/a2ps/
Best regards,
Akim
--
P-mail: Akim Demaille, 107 rue Bobillot, F-75013 Paris, France
E-mail: demaille@inf.enst.fr
V-mail: +33 (1) 45-81-78-68
--Multipart_Mon_Oct_20_10:52:55_1997-1--
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: Bug in CC? (OSF1 4.0)
1997-10-20 4:00 Bug in CC? (OSF1 4.0) Akim Demaille
@ 1997-10-20 4:00 ` Rich Peterson
1997-10-21 4:00 ` Akim Demaille
1 sibling, 0 replies; 3+ messages in thread
From: Rich Peterson @ 1997-10-20 4:00 UTC (permalink / raw)
To: Akim Demaille
Akim Demaille wrote:
> One of the problems I encounter is a weird behavior of native
> cc. On the attached file (cc -E of the file giving problems), I get
> the following problems:
>
> $ cc foo.c -c
> cc: Error: foo.c, line 534: In this declaration, the type of
> "ds_strccat" is not compatible with the type of a previous declaration
> of "ds_strccat" at line number 339 in file foo.c.
> ds_strccat (struct dstring *s, char c)
> ^
> cc: Error: foo.c, line 624: In this declaration, the type of
> "ds_getdelim" is not compatible with the type of a previous
> declaration of "ds_getdelim" at line number 353 in file foo.c.
> char *
> -----^
>
> $ uname -a
> OSF1 elecsrv.enst.fr V4.0 464 alpha
>
> The line 534 is
> void /* 533 */
> ds_strccat (struct dstring *s, char c)
>
> and 339 is
>
> void ds_strccat ();
>
> Can somebody explain me what is going on? The other is
> identical. I have no problem with the other functions!
The compiler is correct in issuing a diagnostic for this code.
The problem is that one function declaration uses ANSI C prototype
syntax to specify the types of the parameters, the other declaration
is an old K&R-style declaration,
and the prototype-style declaration does not specify parameter
types that are compatible with the types that result from the
application of the default argument promotions.
See section 3.5.4.3 of the ANSI version of the standard (6.5.4.3
of the ISO version).
In particular, line 534 says the second parameter to ds_strccat
is of type char, while the declaration at line 339 provides no
parameter information. Suppose you had only the second declaration
present and had the following code:
extern void ds_strccat ();
extern char x;
void foo(void) {
ds_strccat(0, x);
}
The compiler is required to fetch the value of the char variable
x, promote it to type int, and pass the value to ds_strccat
as an int.
If you had only the first declaration:
extern void ds_strccat (struct dstring *s, char c);
extern char x;
void foo(void) {
ds_strccat(0, x);
}
The compiler is required to fetch the value of the char variable
x, and pass it to ds_strccat as a char.
Compilers are permitted to use different calling conventions to
pass a char value versus an int value, so your declarations
are specifying two conflicting ways to generate code for calls
to the same function. As it happens, the Digital UNIX C
compiler does not use very different conventions for char
and int parameters, but under certain circumstances you could
get somewhat different results (e.g. because the high order
bits in the 64-bit register can be left with garbage if the
compiler knows that only the low-order 8 bits are used). From
the C language point of view, though, the two declarations are
just as incompatible as if one said the parameter was float and
the other said it was int.
If you have lots of other functions that are declared twice,
once in prototype-style and the other old-style, and the compiler
does not complain about them, then those prototype declarations
must be specifying only parameter types that are compatible with
the types that result from the default argument promotions
(i.e. flavors of int, long, double, pointers, and structs or unions).
-Rich
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: Bug in CC? (OSF1 4.0)
1997-10-20 4:00 Bug in CC? (OSF1 4.0) Akim Demaille
1997-10-20 4:00 ` Rich Peterson
@ 1997-10-21 4:00 ` Akim Demaille
1 sibling, 0 replies; 3+ messages in thread
From: Akim Demaille @ 1997-10-21 4:00 UTC (permalink / raw)
Akim Demaille <demaille@gargantua.enst.fr> writes:
> Hi !
>
> One of the problems I encounter is a weird behavior of native
> cc. On the attached file (cc -E of the file giving problems), I get
> the following problems:
>
> $ cc foo.c -c
> cc: Error: foo.c, line 534: In this declaration, the type of
> "ds_strccat" is not compatible with the type of a previous declaration
> of "ds_strccat" at line number 339 in file foo.c.
> ds_strccat (struct dstring *s, char c)
> ^
>
> The line 534 is
> void /* 533 */
> ds_strccat (struct dstring *s, char c)
>
> and 339 is
>
> void ds_strccat ();
Several persons answered my question. I thank them a lot, and
apologize for my mistake. Weirdness was purely due to my
miscomprehension of mixed KnR and ANSI style.
Everything comes from the fact that :
- my does-the-compiler-handle-prototypes macros were ill defined,
removing prototypes to often,
- I thought there were no problems with that.
It appears that only two functions in the file I sent were
using char as parameters, but leaving undefined the arguments in the
prototype resulted in having them defaulted to an int type.
It breaks on char (and short int, floats I guess, etc.). Any
compiler would have behaved this way.
To fix my problem I only had to fix my prototypes defining
macros so that they... work :).
Once again, thanks a lot to those who answered.
Akim
PS/ I have a question then: how would a KnR compiler would have
behaved?
--
P-mail: Akim Demaille, 107 rue Bobillot, F-75013 Paris, France
E-mail: demaille@inf.enst.fr
V-mail: +33 (1) 45-81-78-68
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1997-10-21 4:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1997-10-20 4:00 Bug in CC? (OSF1 4.0) Akim Demaille
1997-10-20 4:00 ` Rich Peterson
1997-10-21 4:00 ` Akim Demaille
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox