473,771 Members | 2,297 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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)cybers pace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #1
9 2734
Christopher Benson-Manica <at***@nospam.c yberspace.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)cybers pace.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**********@c hessie.cirr.com >,
Christopher Benson-Manica <at***@nospam.c yberspace.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******@csclu b.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)cybers pace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #5
Dave Vandervies wrote:
In article <cm**********@c hessie.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************ *********@c13g2 000cwb.googlegr oups.com>,
Jane Andrews <ja**********@g mail.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************ **********@z14g 2000cwz.googleg roups.com> "Jane Andrews" <ja**********@g mail.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.c yberspace.org> wrote in message news:<cm******* ***@chessie.cir r.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
3468
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 if the default constructor left the values uninitialized. void f() {
204
13101
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 = {0,1,2,4,9};
7
11930
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 oResponse.historicalData.Length - 1 ) no problem to load a datagrid. However, when I try to bind directly the datasource to the web service
1
4986
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 get the following xml from the server ===================================================
104
17008
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 that array Could you show me a little example how to do this? Thanks.
2
2931
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 imaginary portions. To this end I have some dynamic arrays of doubles to hold the standardized individual rael and imaginary parts. double *ANreal, *ANimag, *BNreal, *BNimag, *CNreal, *CNimag; ANreal = new double; ANimag = new double;
1
9509
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 element, and the last element are known to be 0. I've implemented a -operator that returns a ComplexReference object that basically maps a complex<doubleinto the storage used in the array. What I would like to do is using the ComplexReference...
6
1667
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 p-->p-->p p
4
4291
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
9619
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10260
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10102
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6712
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.