Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #66090

Re: Error messages

From David Brown <david.brown@hesbynett.no>
Newsgroups comp.lang.c
Subject Re: Error messages
Date 2015-07-21 11:40 +0200
Organization A noiseless patient Spider
Message-ID <mol3vp$ptd$1@dont-email.me> (permalink)
References (1 earlier) <moa2c9$lir$1@dont-email.me> <moabue$e75$1@dont-email.me> <6e397d0b-4082-4915-97e1-0db8020b4241@googlegroups.com> <ln615ihz3g.fsf@kst-u.example.com> <50f83997-f446-4ad1-a418-f35d51f0bd1f@googlegroups.com>

Show all headers | View raw


On 19/07/15 03:29, David Kleinecke wrote:
> On Friday, July 17, 2015 at 9:25:01 PM UTC-7, Keith Thompson wrote:
>> David Kleinecke <dkleinecke@gmail.com> writes:
>> [...]
>>> A compiler implementation could have a dictionary of all the identifiers
>>> in the Standard Library (and feel free to extend to any other units 
>>> you like) so that if it sees an identifier in a position where it is not
>>> being declared it could search for the identifier in the dictionary and 
>>> add the needed header before proceeding. The compiler must emit a 
>>> message (warning?) teeling you what it did.  
>>>
>>> Anybody ever done that?
>>
>> Certainly.
>>
>> $ cat c.c
>> int main(void) {
>>     printf("hello\n");
>> }
>> $ c gcc -c c.c
>> c.c: In function 'main':
>> c.c:2:5: warning: incompatible implicit declaration of built-in function
>> 'printf' [enabled by default]
>>      printf("hello\n");
>        ^
> 
> Well at least it recognized that "printf" was a library (built-in!)
> function. It didn't, as I asked, correct the code and continue. The 
> error description is very confusing. At that position the statement 
> cannot be a function declaration because it's inside a compound 
> statement. The compliler seems to think it is the old (now dropped) 
> form of a function definition.
> 

No, the compiler does not think "printf("hello\n");" is a declaration -
nor does the error message suggest that.  It tells you that the
/implicit/ declaration - i.e., the one that is assumed but not given
explicitly - is incompatible with the "builtin declaration".  (gcc
builtin declarations are a bit weird, in that the compiler checks for
compatibility but you can't use them yourself - you still need a proper
declaration.)

> But it does not make the easy repair and continue.

"Repairing and continuing" is a terrible idea, though trying to avoid
spurious extra diagnostics as a follow-on is useful.  If you want to
look at this sort of thing in practice, try clang or recent versions of
gcc (diagnostics have improved significantly in the past few versions),
especially with -Wall -Wextra, and perhaps some of the other warning
flags according to taste.

> 
>> It happens to do this for "printf" but not for FILE -- though if you
>> write
>>
>>     FILE *tmp;
>>
>> without the proper #include, it does recognize that it's a type name.
>  
> It sounds like the libraray identifier data base may only cover
> function names. It is inconvenient for me to run a test just now -
> does it recognize a macro, say, EOF or NULL, without an #include?  
> 

gcc does not have a database of standard library identifiers - it is
designed to work with a range of libraries, including freestanding
(i.e., not hosted) libraries that may be very much smaller than the full
C library.

But it has "builtins" for a number of common standard library functions,
in order to improve optimisation.  For example, it has built-in support
for memcpy which allows it to optimise calls to memcpy into loops, or to
optimise "printf("Hello\n");" into "puts("Hello\n")", as well as
allowing it to perform additional checking such as matching printf
specifiers with actual parameters.  The real work behind printf and
friends is still carried out by the library function, and you still need
to declare the functions properly before using them.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Error messages jacobnavia <jacob@jacob.remcomp.fr> - 2015-07-17 02:36 +0200
  Re: Error messages Richard Heathfield <rjh@cpax.org.uk> - 2015-07-17 01:51 +0100
    Re: Error messages Keith Thompson <kst-u@mib.org> - 2015-07-16 18:24 -0700
      Re: Error messages Lőrinczy Zsigmond <nospam@for.me> - 2015-07-17 09:31 +0200
        Re: Error messages Richard Heathfield <rjh@cpax.org.uk> - 2015-07-17 08:35 +0100
          Re: Error messages glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-07-17 09:11 +0000
            Re: Error messages Richard Heathfield <rjh@cpax.org.uk> - 2015-07-17 10:30 +0100
            Re: Error messages Ian Collins <ian-news@hotmail.com> - 2015-07-17 21:44 +1200
              Re: Error messages Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-17 12:55 +0100
              Re: Error messages Melzzzzz <mel@zzzzz.com> - 2015-07-17 19:53 +0200
              Re: Error messages glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-07-17 17:55 +0000
                Re: Error messages James Kuyper <jameskuyper@verizon.net> - 2015-07-17 14:19 -0400
            Re: Error messages raltbos@xs4all.nl (Richard Bos) - 2015-07-19 21:44 +0000
        Re: Error messages gazelle@shell.xmission.com (Kenny McCormack) - 2015-07-17 07:38 +0000
          Re: Error messages Noob <root@127.0.0.1> - 2015-07-17 09:58 +0200
            Re: Error messages gazelle@shell.xmission.com (Kenny McCormack) - 2015-07-17 13:32 +0000
      Re: Error messages Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-18 11:13 +0100
  Re: Error messages James Kuyper <jameskuyper@verizon.net> - 2015-07-16 22:36 -0400
  Re: Error messages Reinhardt Behm <rbehm@hushmail.com> - 2015-07-17 13:05 +0800
    Re: Error messages jacobnavia <jacob@jacob.remcomp.fr> - 2015-07-17 09:48 +0200
      Re: Error messages David Kleinecke <dkleinecke@gmail.com> - 2015-07-17 19:23 -0700
        Re: Error messages Keith Thompson <kst-u@mib.org> - 2015-07-17 21:24 -0700
          Re: Error messages David Kleinecke <dkleinecke@gmail.com> - 2015-07-18 18:29 -0700
            Re: Error messages Keith Thompson <kst-u@mib.org> - 2015-07-18 20:59 -0700
              Re: Error messages David Kleinecke <dkleinecke@gmail.com> - 2015-07-19 19:22 -0700
            Re: Error messages David Brown <david.brown@hesbynett.no> - 2015-07-21 11:40 +0200
              Compiler conformance (Was: Error messages) gazelle@shell.xmission.com (Kenny McCormack) - 2015-07-21 11:40 +0000
                Re: Compiler conformance Noob <root@127.0.0.1> - 2015-07-21 14:01 +0200
                Re: Compiler conformance gazelle@shell.xmission.com (Kenny McCormack) - 2015-07-21 13:47 +0000
        Re: Error messages Reinhardt Behm <rbehm@hushmail.com> - 2015-07-18 13:38 +0800
    Re: Error messages Keith Thompson <kst-u@mib.org> - 2015-07-17 07:54 -0700
      Re: Error messages raltbos@xs4all.nl (Richard Bos) - 2015-07-19 22:00 +0000
        Re: Error messages Richard Damon <Richard@Damon-Family.org> - 2015-07-19 19:47 -0400
  Re: Error messages jacobnavia <jacob@jacob.remcomp.fr> - 2015-07-17 10:06 +0200
  Re: Error messages Bartc <bc@freeuk.com> - 2015-07-17 12:07 +0100
  Re: Error messages Noob <root@127.0.0.1> - 2015-07-17 13:14 +0200
    Re: Error messages Bartc <bc@freeuk.com> - 2015-07-17 12:40 +0100
  Re: Error messages gwowen <gwowen@gmail.com> - 2015-07-17 04:32 -0700
    Re: Error messages jacobnavia <jacob@jacob.remcomp.fr> - 2015-07-17 14:15 +0200
      Re: Error messages gwowen <gwowen@gmail.com> - 2015-07-17 05:25 -0700
        Re: Error messages Bartc <bc@freeuk.com> - 2015-07-17 13:34 +0100
          Re: Error messages Keith Thompson <kst-u@mib.org> - 2015-07-17 08:07 -0700
        Re: Error messages jacobnavia <jacob@jacob.remcomp.fr> - 2015-07-17 14:38 +0200
          Re: Error messages Martin Shobe <martin.shobe@yahoo.com> - 2015-07-17 08:50 -0500
            Re: Error messages jacobnavia <jacob@jacob.remcomp.fr> - 2015-07-17 16:08 +0200
              Re: Error messages Martin Shobe <martin.shobe@yahoo.com> - 2015-07-17 09:24 -0500
                Re: Error messages James Kuyper <jameskuyper@verizon.net> - 2015-07-17 12:26 -0400
                Re: Error messages Martin Shobe <martin.shobe@yahoo.com> - 2015-07-17 13:19 -0500
                Re: Error messages James Kuyper <jameskuyper@verizon.net> - 2015-07-17 14:28 -0400
                Re: Error messages James Kuyper <jameskuyper@verizon.net> - 2015-07-17 14:43 -0400
                Re: Error messages Bartc <bc@freeuk.com> - 2015-07-17 20:31 +0100
                Re: Error messages Martin Shobe <martin.shobe@yahoo.com> - 2015-07-18 08:41 -0500
                Re: Error messages David Brown <david.brown@hesbynett.no> - 2015-07-21 12:25 +0200
                Re: Error messages James Kuyper <jameskuyper@verizon.net> - 2015-07-21 13:20 -0400
                Re: Error messages David Brown <david.brown@hesbynett.no> - 2015-07-22 00:05 +0200
          Re: Error messages Noob <root@127.0.0.1> - 2015-07-17 16:16 +0200
            Re: Error messages doctor@doctor.nl2k.ab.ca (The Doctor) - 2015-07-17 14:49 +0000
              Re: Error messages Noob <root@127.0.0.1> - 2015-07-17 20:02 +0200
                Re: Error messages The Doctor <doctor@doctor.nl2k.ab.ca> - 2015-07-17 22:24 +0000
                Re: Error messages Noob <root@127.0.0.1> - 2015-07-20 10:46 +0200
                Re: Error messages doctor@doctor.nl2k.ab.ca (The Doctor) - 2015-07-20 14:59 +0000
          Re: Error messages Keith Thompson <kst-u@mib.org> - 2015-07-17 08:25 -0700
      Re: Error messages raltbos@xs4all.nl (Richard Bos) - 2015-07-19 22:07 +0000
  Re: Error messages Ed Prochak <edprochak@gmail.com> - 2015-07-17 20:11 -0700

csiph-web