473,382 Members | 1,376 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Complex array definition

Recently, the following definition was posted to comp.lang.c++:
char **Arr[3][2];


1) Is the type of this object "array of 3 (array of two of pointer to
pointer to char)"? If not, what is it?

2) Could the object be passed to functions with the given prototypes?

void foo( char **bar[][2] ); /* yes? */
void baz( char ****bar ); /* no? */
void quux( char **(*)bar[2] ); /* yes...? */

I don't know if the last is even legal; hence the question.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #1
9 2708
Christopher Benson-Manica <at***@nospam.cyberspace.org> spoke thus:
void quux( char **(*)bar[2] ); /* yes...? */ I don't know if the last is even legal; hence the question.


Perhaps I intended to write

void quux( char **(bar*)[2] );

although the question still stands.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #2
i think char **bar[2][3] is a two dimentional array of double pointers
(pointer to a pointer that points to a char). i believe it was just a
mistake, he really wanted to create a 2-d array of chars, and only needed
to delcar:
char **twodarray;
as for weather or not those are legal ways of passing the **char[][] to a
function, i don't know.

Nov 14 '05 #3
In article <cm**********@chessie.cirr.com>,
Christopher Benson-Manica <at***@nospam.cyberspace.org> wrote:
Recently, the following definition was posted to comp.lang.c++:
char **Arr[3][2];
1) Is the type of this object "array of 3 (array of two of pointer to
pointer to char)"? If not, what is it?


Yes.
Quoth cdecl:
cdecl> explain char **arr[3][2]
declare arr as array 3 of array 2 of pointer to pointer to char

2) Could the object be passed to functions with the given prototypes?

void foo( char **bar[][2] ); /* yes? */
Correct. The empty [] in the function declaration are just syntactic
sugar for a pointer, and the type described is the same type as the array
name decays to (array of foo -> pointer to foo), "pointer to array[2]
of pointer to pointer to char".
Quoth cdecl:
cdecl> explain char **bar[][2]
declare bar as array of array 2 of pointer to pointer to char

void baz( char ****bar ); /* no? */
Correct. "pointer to array" does not decay to "pointer to pointer",
so the conversion here is illegal.

void quux( char **(*)bar[2] ); /* yes...? */

I don't know if the last is even legal; hence the question.


'Tisn't, and neither is your correction in your other post, but I suspect
you may have meant:
void quux( char **(*bar)[2] );
which describes the same type that foo() takes (and that the array name
decays to), without using empty-[]-in-prototype-means-pointer.
Quoth cdecl:
cdecl> explain char **(*bar)[2]
declare bar as pointer to array 2 of pointer to pointer to char
dave

--
Dave Vandervies dj******@csclub.uwaterloo.ca
[Y]our left hand is currently stopping string 2 fret 1, which is the note
C, so I guess this thread is about as topical as several other comp.lang.c
threads at present. --Richard Heathfield in comp.lang.c
Nov 14 '05 #4
Dave Vandervies <dj******@csclub.uwaterloo.ca> spoke thus:
Quoth cdecl:


I suspect I should have been aware of cdecl before, but at least I got
a chance to show some level of intelligence without using it. Thanks
for your answers.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #5
Dave Vandervies wrote:
In article <cm**********@chessie.cirr.com>,
Quoth cdecl:
cdecl> explain char **arr[3][2]
declare arr as array 3 of array 2 of pointer to pointer to char


<snip>

Hi,
I am a newbie C learner. Could you tell me what 'cdecl' is and how to
use it? Everyone in this group seems to know it except me.
~Jane

Nov 14 '05 #6
In article <10*********************@c13g2000cwb.googlegroups. com>,
Jane Andrews <ja**********@gmail.com> wrote:
Dave Vandervies wrote:
Quoth cdecl:
cdecl> explain char **arr[3][2]
declare arr as array 3 of array 2 of pointer to pointer to char
<snip>

Hi,
I am a newbie C learner. Could you tell me what 'cdecl' is and how to
use it? Everyone in this group seems to know it except me.


It's a program that understands enough C, and a large enough (though
highly structured and limited) subset of English, to translate between C
declarations (hence the name) and something slightly more human-readable
and -writeable.

It does two things that are useful for making sure you're right before
claiming something in comp.lang.c and for determining (by the fact that
you need them) that it's time to throw some typedefs at your code to
make it clearer:

explain <C>
will attempt to parse the C declaration you give it and give you an
English description of the type being declared (or, if it can't parse it,
gives the Very Helpful message "syntax error").
F'rexample:
--------
cdecl> explain int *p
declare p as pointer to int
--------

declare <name> as <English>
will attempt to identify the type you described and output a C declaration
of that type. F'rexample:
--------
cdecl> declare p as pointer to int
int *p
--------
It's actually only really a useful tool for language-lawyering or for
decoding code old enough that you can't hunt down and kill the programmer
who originally wrote it; if you think you need it for writing new code,
what you really need is to clean up and/or give better documentation
for the declarations.
dave

--
Dave Vandervies dj******@csclub.uwaterloo.caI am trying to move 3 bits from left to right with >> operator

Try holding the 3 bits in place, but shift the rest of your computer's memory
right to left. --Kaz Kylheku gives stupid answers to stupid questions in CLC
Nov 14 '05 #7
That was very helpful. Thank You. I have just one more query. Where do
I get this program? :D
-Jane

Nov 14 '05 #8
In article <10**********************@z14g2000cwz.googlegroups .com> "Jane Andrews" <ja**********@gmail.com> writes:
That was very helpful. Thank You. I have just one more query. Where do
I get this program? :D


With some OS's it comes along. Otherwise:
<http://sources.isc.org/devel/tools/cdecl.txt> for instance.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Nov 14 '05 #9
Christopher Benson-Manica <at***@nospam.cyberspace.org> wrote in message news:<cm**********@chessie.cirr.com>...
Recently, the following definition was posted to comp.lang.c++:
char **Arr[3][2];
1) Is the type of this object "array of 3 (array of two of pointer to
pointer to char)"? If not, what is it?


Here's how to deconstruct it.

Arr -- Arr
Arr[3] -- is a 3-element array
Arr[3][2] -- of 2-element arrays
*Arr[3][2] -- of pointers
**Arr[3][2] -- to pointers
char **Arr[3][2] -- to char

So yes, you got it right.

Whenever you come across a hairy declarator like that, start with the
identifier and work your way out according to operator precedence
(subscripts have higher precedence than indirection, so you know that
Arr is an array of pointers, not a pointer to an array).
2) Could the object be passed to functions with the given prototypes?

void foo( char **bar[][2] ); /* yes? */
Yes.
void baz( char ****bar ); /* no? */
No.
void quux( char **(*)bar[2] ); /* yes...? */

I don't know if the last is even legal; hence the question.


No. Here's how to construct it (again, start with the identifier and
work your way outward according to operator precedence):

bar -- bar
*bar -- is a pointer
(*bar)[2] -- to a 2-element array
*(*bar)[2] -- of pointers
**(*bar)[2] -- to pointers
char **(*bar)[2] -- to char
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Marcin Kalicinski | last post by:
Hi, I found out that default constructor of std::complex class initializes the value to (0,0). I wonder why is it so? Because of this, the code below is about two times slower than it could be...
204
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 =...
7
by: BS | last post by:
Hello everybody I'm calling a webservice that returns complex data. The goal is to populate a datagrid with it. Using a loop for each record found ( such as For i = 0 To...
1
by: GAURAV KRISHNA | last post by:
I am able to deserialize an array using XMLSerializer but the size of an array is 0.The problem seems to be because of unqualified element name but I am not very sure. Here is what I did: I...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
2
by: jccorreu | last post by:
I'm taking in data from multiple files that represents complex numbers for charateristics of different elements. I begin with arrays of doubles and interpolate to get standard values in real and...
1
by: perroe | last post by:
Hi I have a array of complex numbers that are stored in a simple double array. This is done since the array is part of an wrapper for an external C library, and the imaginary part of the first...
6
by: Cric | last post by:
Hi, how can be the declaration of a pointer which points to dynamic array of pointers and each pointer from this array points to an dynamic array of pointers which points to character strings...
4
by: jacob navia | last post by:
Hi Has C++ defined the function isnan() for complex numbers? What is the definition? Thanks in advance -- jacob navia jacob at jacob point remcomp point fr
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.