Topic: int i[]={1,2,3}: what is i here?


Author: jslahtin@vipunen.hut.fi (Jukka S Lahtinen)
Date: 21 Feb 94 22:59:09 GMT
Raw View
grossibr@buran (Michael Gross) writes:

>and linking the program. You only get e real pointer to the array with
>int * x[10].

Humm.. that way you would have an array of ten pointers to int's..
--
+-------------------------------------------------------------------------+
! Jukka S Lahtinen   ! jslahtin@vipunen.hut.fi  !   walker@mits.mdata.fi  !
+-------------------------------------------------------------------------+




Author: grumpy@cbnewse.cb.att.com (Paul J Lucas)
Date: Tue, 22 Feb 1994 00:18:39 GMT
Raw View


Author: gcato@sct.edu (Gene Cato)
Date: 22 Feb 1994 00:18:17 -0500
Raw View
In article <CLLnJ7.CqA@cbnewse.cb.att.com> grumpy@cbnewse.cb.att.com
(Paul J Lucas) writes:
>                                              ... A vector "decays"
> into a constant pointer to the first element in all contexts
> except as an argument to sizeof.

It also retains its full identity if it is passed by reference to a function.

  Until Later,
  Vaughn Cato (gcato@st6000.sct.edu)




Author: anders@munin.his.se (Anders Eklund)
Date: 22 Feb 94 15:15:42 GMT
Raw View
In article <2kbat0$5kr@brachio.zrz.TU-Berlin.DE> grossibr@buran (Michael Gross) writes:

>   As I have learned through many hours of investigation in the deep of C++,
>   There is no difference in the way C++ does with integer or char-arrays.
>   An int x[10] seemed just to be the same as a char x[20]

Well, not quite true. First of all I think you are used to PC's. Not
all machines have 16-bit integers. The rule is only that

  char <= short int <= int <= long   (in number of bits)

It is quite common that an integer is represented in 32 bits.
Another thing is that the datatype must be used in order for
the compiler to be able to interpret the data area correctly.

>   The variable itself is a pointer, right, but it is a constant pointer to
>   the place the values are, and so it is optimized to a constant when compiling
>   and linking the program. You only get e real pointer to the array with
>   int * x[10].
>
>   Grossibr

You will not get a real pointer to the array with int *x[10]. This
statement means that you will get a constant pointer to an array
with 10 int-pointers. If you want an pointer to an array of 10 int
then you must use the following statement:

  int (*x)[10];

/Anders

--


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         ___
        /   /       /
       /__ /___ ___/___ ___ ___      --  Anders Eklund  anders@ida.his.se --
      /   //  //  //__//   /__       --  Computer Science Department      --
    _/   //  //__//__ /   ___/       --  University of Skovde, Sweden     --

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~







Author: coghlan@bcarh5f8.bnr.ca (Patrick Coghlan)
Date: Tue, 22 Feb 1994 18:19:33 GMT
Raw View
In article <2kbat0$5kr@brachio.zrz.TU-Berlin.DE>, grossibr@buran (Michael Gross) writes:
|> In article <1994Feb21.204604.10525@tin.monsanto.com> raspar@ccmail.monsanto.com writes:
|> >
|> >I have come across an oddity in defining arrays with an initializer.   I
|> >thought that all arrays were pointers, but in this case you cannot do pointer
|> >arithmetic with i, although you can pass it by value in a function.  So what
|> >the hell, is i here.  Also, if you look at sizeof(i), you will see that it is
|> >an array, not a pointer.  What's going on?  I'm not sure if this a C++ feature,
|> >or an ANSI C feature.  Is there such a thing as multi-deimensional integer
|> >type?
|> >
|>
|> As I have learned through many hours of investigation in the deep of C++,
|> There is no difference in the way C++ does with integer or char-arrays.
|> An int x[10] seemed just to be the same as a char x[20]
|> The variable itself is a pointer, right, but it is a constant pointer to
|> the place the values are, and so it is optimized to a constant when compiling
|> and linking the program. You only get e real pointer to the array with
|> int * x[10].

Actually, isn't the "variable" i an array, not a pointer?  References to
i or i[] result in a pointer being generated, but I don't think the
compiler generates a location i which contains a pointer in addition to
locations for the elements of the array.  I am not a C guru, but I think
what I have stated is correct.




Author: bd@mash.GUN.de (Bruno Dickhoff)
Date: 23 Feb 1994 01:00:00 +0100
Raw View
>>
>> I have come across an oddity in defining arrays with an initializer.   I
>> thought that all arrays were pointers, but in this case you cannot do
>> pointer arithmetic with i, although you can pass it by value in a function.
>>  So what the hell, is i here.  Also, if you look at sizeof(i), you will see
>> that it is an array, not a pointer.  What's going on?  I'm not sure if this
>> a C++ feature, or an ANSI C feature.  Is there such a thing as
>> multi-deimensional integer type?
>>

You can often use Arrays like Pointers, but Arrays still are NO pointers.
Some differences still exist.


______________________________________________________________________
| Bruno Dickhoff                    +       Usenet: bd@mash.GUN.de   |
| Maybachstrasse 7                  +   CompuServe: 100140,2231      |
| 40470 Duesseldorf, Germany        +         Fido: 2:2440/224       |
| Voice: +49-211-629934             +++++++++++++++++++++++++++++++++|
| Data : +49-211-628382 (FidoMailer, most of the day...)             |
======================================================================
## CrossPoint v2.93 ##




Author: grossibr@buran (Michael Gross)
Date: 21 Feb 1994 21:59:59 GMT
Raw View
In article <1994Feb21.204604.10525@tin.monsanto.com> raspar@ccmail.monsanto.com writes:
>
>I have come across an oddity in defining arrays with an initializer.   I
>thought that all arrays were pointers, but in this case you cannot do pointer
>arithmetic with i, although you can pass it by value in a function.  So what
>the hell, is i here.  Also, if you look at sizeof(i), you will see that it is
>an array, not a pointer.  What's going on?  I'm not sure if this a C++ feature,
>or an ANSI C feature.  Is there such a thing as multi-deimensional integer
>type?
>

As I have learned through many hours of investigation in the deep of C++,
There is no difference in the way C++ does with integer or char-arrays.
An int x[10] seemed just to be the same as a char x[20]
The variable itself is a pointer, right, but it is a constant pointer to
the place the values are, and so it is optimized to a constant when compiling
and linking the program. You only get e real pointer to the array with
int * x[10].

Grossibr





Author: raspar@ccmail.monsanto.com
Date: Mon, 21 Feb 1994 22:41:12 GMT
Raw View
I have come across an oddity in defining arrays with an initializer.   I
thought that all arrays were pointers, but in this case you cannot do pointer
arithmetic with i, although you can pass it by value in a function.  So what
the hell, is i here.  Also, if you look at sizeof(i), you will see that it is
an array, not a pointer.  What's going on?  I'm not sure if this a C++ feature,
or an ANSI C feature.  Is there such a thing as multi-deimensional integer
type?

Rodney