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


Groups > comp.lang.c > #136612

Re: GCC and const-correctness

From Philipp Klaus Krause <pkk@spth.de>
Newsgroups comp.lang.c
Subject Re: GCC and const-correctness
Date 2018-10-11 11:22 +0200
Organization solani.org
Message-ID <ppn4oj$79c$1@solani.org> (permalink)
References <20181011121731.c7a6e66e8ce7f5410984b007@g{oogle}mail.com>

Show all headers | View raw


Am 11.10.2018 um 11:17 schrieb Anton Shepelev:
> Hello, all
> 
> Shall the following program compile with nary a error nor a
> warning?
> 
> #include <stdio.h>
> static void test( const char * s )
> {}
> 
> int main( int argc, char** argv )
> {  char * s;
>    s = NULL;
>    test( s );
>    return 0;
> }
> 
> I was expecting at least a hint about a violation of const-
> correctness, because test accepts a pointer to const char,
> whereas a pointer to char is passed, but
> 
>    gcc -Wall -Wpedantic
> 
> has no objections.  Why?
> 

An implicit cast adding a const is fine wrt. const-correctness. Only the
opposite would be a problem.

After all, just because something is not const doesn't mean you have to
write it.

Philipp

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


Thread

GCC and const-correctness Anton Shepelev <anton.txt@g{oogle}mail.com> - 2018-10-11 12:17 +0300
  Re: GCC and const-correctness Philipp Klaus Krause <pkk@spth.de> - 2018-10-11 11:22 +0200
    Re: GCC and const-correctness Anton Shepelev <anton.txt@g{oogle}mail.com> - 2018-10-11 13:17 +0300
  Re: GCC and const-correctness Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2018-10-11 02:40 -0700
  Re: GCC and const-correctness Spiros Bousbouras <spibou@gmail.com> - 2018-10-11 10:17 +0000
    Re: GCC and const-correctness Anton Shepelev <anton.txt@g{oogle}mail.com> - 2018-10-11 13:28 +0300
      Re: GCC and const-correctness Spiros Bousbouras <spibou@gmail.com> - 2018-10-11 10:58 +0000
        Re: GCC and const-correctness jameskuyper@alumni.caltech.edu - 2018-10-11 08:21 -0700
    Re: GCC and const-correctness David Brown <david.brown@hesbynett.no> - 2018-10-11 12:39 +0200
    Re: GCC and const-correctness Jorgen Grahn <grahn+nntp@snipabacken.se> - 2018-10-11 15:02 +0000
      Re: GCC and const-correctness Anton Shepelev <anton.txt@g{oogle}mail.com> - 2018-10-11 18:06 +0300
      Re: GCC and const-correctness Wouter Verhelst <w@uter.be> - 2018-10-11 17:23 +0200
        Re: GCC and const-correctness Jorgen Grahn <grahn+nntp@snipabacken.se> - 2018-10-12 10:16 +0000
          Re: GCC and const-correctness David Brown <david.brown@hesbynett.no> - 2018-10-12 13:21 +0200
            Re: GCC and const-correctness Wouter Verhelst <w@uter.be> - 2018-10-13 09:33 +0200
              Re: GCC and const-correctness David Brown <david.brown@hesbynett.no> - 2018-10-13 13:11 +0200
    Re: Empty functions (was: GCC and const-correctness) Wouter Verhelst <w@uter.be> - 2018-10-11 17:25 +0200
      Re: Empty functions (was: GCC and const-correctness) Keith Thompson <kst-u@mib.org> - 2018-10-11 09:23 -0700
        Re: Empty functions (was: GCC and const-correctness) Keith Thompson <kst-u@mib.org> - 2018-10-11 10:54 -0700
        Re: Empty functions (was: GCC and const-correctness) Wouter Verhelst <w@uter.be> - 2018-10-11 19:56 +0200
          Re: Empty functions David Brown <david.brown@hesbynett.no> - 2018-10-11 20:19 +0200
          Re: Empty functions (was: GCC and const-correctness) Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2018-10-12 02:43 -0700
    Re: Empty functions (was: GCC and const-correctness) Anton Shepelev <ant0n.txt@gmai1.c0m> - 2018-10-11 19:16 +0300

csiph-web