The following creates a function "test" that takes a parameter that is
a pointer to a multi dimensional array.
typedef int int_arr[][3];
void test(int_arr *foo) {
printf("%d\n", (*foo)[1][2]);
}
int main() {
int a[2][3]= {1,2,3,4,5,6};
test(&a);
}
However, how do I specify this, if I don't want to use the typedef?
E.g what I would LIKE to do is:
void test(int[][3] *foo) {...}
However this produces a parse error. Is there any way to avoid typedefing?
--
Michael Birkmose - stud.polyt
Aalborg University - Department of Computer Science
Fredrik Bajers Vej 7, B1-215 6 2756
On Tue, 11 May 2004, Michael Birkmose wrote: The following creates a function "test" that takes a parameter that is a pointer to a multi dimensional array.
typedef int int_arr[][3];
void test(int_arr *foo) { printf("%d\n", (*foo)[1][2]); }
However, how do I specify this, if I don't want to use the typedef?
This is Rule Number One of C: Declaration mimics use.
You wrote (*foo)[x][y] to use 'foo'; now write (*foo)[x][y] to
declare 'foo'. And since (*foo)[x][y] is an 'int', stick an
'int' in front so the compiler knows what type it is.
void test(int (*foo)[][3]) {
printf("%d\n", (*foo)[1][2]);
}
Simple, huh?
-Arthur
Michael Birkmose wrote: The following creates a function "test" that takes a parameter that is a pointer to a multi dimensional array.
typedef int int_arr[][3];
void test(int_arr *foo) { printf("%d\n", (*foo)[1][2]); }
int main() { int a[2][3]= {1,2,3,4,5,6}; test(&a); }
However, how do I specify this, if I don't want to use the typedef?
E.g what I would LIKE to do is: void test(int[][3] *foo) {...}
However this produces a parse error. Is there any way to avoid typedefing?
void test(int (*foo)[][3]) { ... }
Are you sure this is what you want to do, though? The
extra level of indirection doesn't seem to be necessary, and
you could instead write
void test(int foo[][3]) { ... }
and
test(foo);
without the `&' operator.
-- Er*********@sun.com
Michael Birkmose <bi******@cs.auc.dk> writes: typedef int int_arr[][3];
void test(int_arr *foo) { printf("%d\n", (*foo)[1][2]); }
However, how do I specify this, if I don't want to use the typedef?
You should get a copy of the cdecl program. Example session:
blp@blp:~(0)$ cdecl
Type `help' or `?' for help
cdecl> declare pointer to array of array 3 of int
int (*var)[][3]
cdecl> quit
blp@blp:~(0)$
--
"The lusers I know are so clueless, that if they were dipped in clue
musk and dropped in the middle of pack of horny clues, on clue prom
night during clue happy hour, they still couldn't get a clue."
--Michael Girdwood, in the monastery
Ben Pfaff wrote: Michael Birkmose <bi******@cs.auc.dk> writes:
typedef int int_arr[][3];
void test(int_arr *foo) { printf("%d\n", (*foo)[1][2]); }
However, how do I specify this, if I don't want to use the typedef?
You should get a copy of the cdecl program. Example session:
blp@blp:~(0)$ cdecl Type `help' or `?' for help cdecl> declare pointer to array of array 3 of int int (*var)[][3] cdecl> quit blp@blp:~(0)$
Ben, where can I find cdecl.c source? I have my own versions of decl
and undecl from K&R2 examples but not a complete program. Please.
--
Joe Wright mailto:jo********@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Joe Wright <jo********@comcast.net> writes: Ben, where can I find cdecl.c source? I have my own versions of decl and undecl from K&R2 examples but not a complete program. Please.
Google for cdecl, or for cdecl.tar.gz. I note that one of the
hits lists "Chris Torek" as submitter--in 1986.
--
"Give me a couple of years and a large research grant,
and I'll give you a receipt." --Richard Heathfield
>Joe Wright <jo********@comcast.net> writes: Ben, where can I find cdecl.c source? I have my own versions of decl and undecl from K&R2 examples but not a complete program. Please.
In article <87************@blp.benpfaff.org>
Ben Pfaff <bl*@cs.stanford.edu> writes:Google for cdecl, or for cdecl.tar.gz. I note that one of the hits lists "Chris Torek" as submitter--in 1986.
I will note here that I did not write it, but I did some minor work
on a version of it at some point, presumably shortly before submitting
it in 1986. :-)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Robin Sanderson |
last post by:
Sorry in advance if this is a stupid question - I am new to C++.
In the process of converting program to be run from the command line
into a function to be run from another program I noticed...
|
by: Simon |
last post by:
I'm a js newbie trying to use some very simple js to call an ActiveX
object's methods.
I need to use a pointer to call an embedded ActiveX object's method to
receive a number.
As I understand it,...
|
by: pandapower |
last post by:
Hi,
I know about the equivalence of pointer and arrays.But my doubt
comes when its for multidimentional arrays.I have read the C faq but
still have some doubts.
Suppose I have a declaration as...
|
by: Peter Ammon |
last post by:
It's my understanding that the printf() function is declared as
int printf(const char * restrict format, ...);
in stdio.h. And loosely speaking, if a parameter is declared as
restricted, then...
|
by: entitledX |
last post by:
Hi, I'm trying to use the HDF library to read a few HDF files that I
need to process. The data in each file varies in rows, but the
columns remain constant. Because of that, I had dynamically...
| |
by: Martin Jørgensen |
last post by:
Hi,
"C primer plus" p.382:
Suppose we have this declaration:
int (*pa);
int ar1;
int ar2;
int **p2;
|
by: I.M. !Knuth |
last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until
I started goofing around with this:
...
|
by: xdevel |
last post by:
Hi, if I have:
int a=100, b = 200, c = 300;
int *a = {&a, &b, &c};
than say that:
int **b is equal to int *a is correct????
|
by: shuisheng |
last post by:
Dear All,
The problem of choosing pointer or reference is always confusing me.
Would you please give me some suggestion on it. I appreciate your kind
help.
For example, I'd like to convert a...
|
by: Szabolcs Borsanyi |
last post by:
Deal all,
The type
typedef double ***tmp_tensor3;
is meant to represent a three-dimensional array. For some reasons the
standard array-of-array-of-array will not work in my case.
Can I...
|
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,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |
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...
|
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 ...
| |