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


Groups > comp.lang.c > #59139

Re: Variadic functions and const

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: Variadic functions and const
Date 2015-03-28 15:13 +0000
Organization A noiseless patient Spider
Message-ID <87384p889t.fsf@bsb.me.uk> (permalink)
References <8fdc6e6e-6160-4ec8-b910-971c96445e67@googlegroups.com>

Show all headers | View raw


samuelallenalexander@gmail.com writes:

> Really surprised I can't find this discussed anywhere.  In a C
> variadic function's prototype, is there any way to specify the const
> status of the variables?  It doesn't seem like there is.

Actually you are asking about the const status of the things pointed to
by the arguments.

But this is to pick an point to contest -- you can't get any type
information about the arguments at all!  In your example, passing a
int * would be as bad as passing a char * and passing an in or float
would probably be worse.

<snip>
> But there's nothing in the prototype warning people (or compilers)
> that const char *'s shouldn't be passed to this function.  Is the
> above nullify_strings function valid?  If a naive space alien only had
> access to printf's prototype, but not to its man pages, would that
> alien be able to deduce that printf("%s","Hello World") is safe?

No.  But then the same is true of thousands of other cases:

  strcpy(x, 0);
  malloc(0);
  strcat("abc", "def");
  memcpy(x, x + 1, 1);

C is very weakly typed and a function prototype says very little about
what calls are safe.

-- 
Ben.

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


Thread

Variadic functions and const samuelallenalexander@gmail.com - 2015-03-28 05:54 -0700
  Re: Variadic functions and const Lőrinczy Zsigmond <nospam@for.me> - 2015-03-28 14:38 +0100
  Re: Variadic functions and const Richard Damon <Richard@Damon-Family.org> - 2015-03-28 10:02 -0400
  Re: Variadic functions and const Kaz Kylheku <kaz@kylheku.com> - 2015-03-28 14:11 +0000
  Re: Variadic functions and const Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-03-28 15:13 +0000
  Re: Variadic functions and const fir <profesor.fir@gmail.com> - 2015-03-28 08:34 -0700
    Re: Variadic functions and const fir <profesor.fir@gmail.com> - 2015-03-28 08:38 -0700
    Re: Variadic functions and const Lőrinczy Zsigmond <nospam@for.me> - 2015-03-28 17:01 +0100
      Re: Variadic functions and const Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-28 12:49 -0700

csiph-web