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


Groups > comp.lang.c > #56956

Re: what is data type 'int *' ?

From glen herrmannsfeldt <gah@ugcs.caltech.edu>
Newsgroups comp.lang.c
Subject Re: what is data type 'int *' ?
Date 2015-02-05 01:24 +0000
Organization Aioe.org NNTP Server
Message-ID <maugoi$g65$1@speranza.aioe.org> (permalink)
References <mauauc$p5v$1@dont-email.me> <87vbjhcj84.fsf@bsb.me.uk>

Show all headers | View raw


Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
> bilsch <king621@comcast.net> writes:
 
>> A Sams book on C programming has a program that demonstrates 
>> how pointers work, similar to the listing below.  
(snip)
>> expects argument of type ???int???, but argument 2 has type ???int *???
 
>> My question is what format specifier (%i) should I use for 
>> type 'int *' ?  I dont know of a format specifier for type ???int *???.
 
> There's no specifier for int * but there is one for void *: %p.  
> Because of the way functions like printf with variable numbers 
> of arguments work, you need to cast the pointer to void * if 
> it is not already of that type:
 
>   printf("\nthe address of var is %p\n", (void *)&var);
 
>> Also, if the compiler used with the book doesnt produce the error, 
>> why is gcc so finicky.  

Early C compilers stored pointers and int the same way, and it
was very common to ignore the difference. Functions with a pointer
argument that was then passed on to another function often declared
one as int.  (That was before void*, though the specific pointer
type could have been used.)

Also, compilers for many years didn't look inside the format
string until run time. 

If (int) and (int*) are the same size, and passed to functions
the same way, it usually works.  As machines with pointer and int
of different size became more popular, there was more need for
the message.

Note that you can cast to (int) and print with %i or %x. The 
conversion is system dependent, but sometimes people know what
it does on the specific system, and find it useful. 
 
> gcc has a history of being cross-platform.  It is stronger than some
> others at pointing out things that are wrong but might just happen to
> work on one system or another.  It's a good thing.  You sound as if you
> think it's the wrong way to go.

-- glen

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


Thread

what is data type 'int  *' ? bilsch <king621@comcast.net> - 2015-02-04 23:45 +0000
  Re: what is data type 'int  *' ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-02-05 00:09 +0000
    Re: what is data type 'int  *' ? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-02-05 01:24 +0000
      Re: what is data type 'int  *' ? James Kuyper <jameskuyper@verizon.net> - 2015-02-05 07:00 -0500
        Re: what is data type 'int  *' ? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-02-05 14:09 +0000
          Re: what is data type 'int  *' ? Robert Wessel <robertwessel2@yahoo.com> - 2015-02-05 13:08 -0600
            Re: what is data type 'int  *' ? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-02-06 00:33 +0000
              Re: what is data type 'int  *' ? Robert Wessel <robertwessel2@yahoo.com> - 2015-02-05 19:30 -0600
                Re: what is data type 'int  *' ? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-02-06 10:17 +0000
                Re: what is data type 'int  *' ? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-02-07 13:21 -0800
  Re: what is data type 'int  *' ? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-02-04 19:47 -0500
    Re: what is data type 'int  *' ? bilsch <king621@comcast.net> - 2015-02-05 09:40 +0000
      Re: what is data type 'int  *' ? Richard Heathfield <rjh@cpax.org.uk> - 2015-02-05 09:51 +0000
    Re: what is data type 'int  *' ? Keith Thompson <kst-u@mib.org> - 2015-02-05 08:04 -0800
      Re: what is data type 'int  *' ? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-02-06 00:42 +0000
        Re: what is data type 'int  *' ? Keith Thompson <kst-u@mib.org> - 2015-02-05 19:09 -0800
  Re: what is data type 'int  *' ? Kaz Kylheku <kaz@kylheku.com> - 2015-02-05 01:17 +0000
  Re: what is data type 'int  *' ? Richard Heathfield <rjh@cpax.org.uk> - 2015-02-05 03:04 +0000
    Re: what is data type 'int  *' ? Richard Heathfield <rjh@cpax.org.uk> - 2015-02-05 03:06 +0000
  Re: what is data type 'int  *' ? Richard Heathfield <rjh@cpax.org.uk> - 2015-02-05 03:06 +0000
    Re: what is data type 'int  *' ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-02-05 10:20 +0000
      Re: what is data type 'int  *' ? Richard Heathfield <rjh@cpax.org.uk> - 2015-02-05 10:47 +0000
        Re: what is data type 'int  *' ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-02-05 12:18 +0000
          Re: what is data type 'int  *' ? Richard Heathfield <rjh@cpax.org.uk> - 2015-02-05 12:40 +0000
      Re: what is data type 'int  *' ? Keith Thompson <kst-u@mib.org> - 2015-02-05 08:24 -0800
        Re: what is data type 'int  *' ? James Kuyper <jameskuyper@verizon.net> - 2015-02-05 11:42 -0500
        Re: what is data type 'int  *' ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-02-05 17:13 +0000
    Re: what is data type 'int  *' ? Keith Thompson <kst-u@mib.org> - 2015-02-05 08:43 -0800
  Re: what is data type 'int  *' ? bilsch <king621@comcast.net> - 2015-02-05 09:45 +0000
  THANKS FOR THE INFO bilsch <king621@comcast.net> - 2015-02-05 09:47 +0000

csiph-web