473,399 Members | 3,832 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,399 software developers and data experts.

Passing a 2D array as a pointer to a pointer

Say I have a function like this.

int Func(float **fppArg);

and I have a variable defined thus.

float faa2DArray[3][3];

How would I pass faa2DArray to Func()?

Many thanks in advance,
Peter.
Aug 27 '08 #1
3 1413
PeterOut <Ma**********@excite.comwrites:
Say I have a function like this.

int Func(float **fppArg);

and I have a variable defined thus.

float faa2DArray[3][3];

How would I pass faa2DArray to Func()?
You can't, at least not directly. You can write:

float *tmp[] = { faa2DArray[0], faa2DArray[1], faa2DArray[2] };
Func(tmp);

or even:

Func((float *[]){faa2DArray[0], faa2DArray[1], faa2DArray[2]});

if you don't mind straying into C99. This is more universal:

float *tmp[3];
tmp[0] = faa2DArray[0];
tmp[1] = faa2DArray[1];
tmp[2] = faa2DArray[2];
Func(tmp);

However, the fact that you need these gymnastics suggests that
something has gone wrong. Can't you start with the right shape of
array in the first place, or change Func to take the array you have?

--
Ben.
Aug 27 '08 #2
PeterOut wrote:
Say I have a function like this.

int Func(float **fppArg);

and I have a variable defined thus.

float faa2DArray[3][3];

How would I pass faa2DArray to Func()?
You wouldn't. You have to change the declaration of either fppArg or
faa2DArray.
One way would be:

int Func(float fppArg[][3]);

Brian
Aug 27 '08 #3
On 27 Aug, 23:53, PeterOut <MajorSetb...@excite.comwrote:
Say I have a function like this.

int Func(float **fppArg);

and I have a variable defined thus.

float faa2DArray[3][3];

How would I pass faa2DArray to Func()?
http://c-faq.com/

FAQ 6.18 "My compiler complained when I passed a two-dimensional
array to a function expecting a pointer to a pointer. "

then read all of section 6. Then read the rest of the FAQ.

--
Nick Keighley

"Resistance is futile. Read the C-faq."
-- James Hu (c.l.c.)
Aug 28 '08 #4

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

Similar topics

58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
9
by: justanotherguy63 | last post by:
Hi, I am designing an application where to preserve the hierachy and for code substitability, I need to pass an array of derived class object in place of an array of base class object. Since I...
8
by: kalinga1234 | last post by:
there is a problem regarding passing array of characters to another function(without using structures,pointer etc,).can anybody help me to solve the problem.
2
by: Newsgroup Posting ID | last post by:
i'm new to c and have gotten my program to run but by passing hardcoded array sizes through the routines, i want to make the array extendable by using realloc but i'd be doing it two routines down,...
11
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to...
2
by: sonaliagr | last post by:
I am trying to update a msg array in function by passing the address but it is showing an error. and also, i want the value of msg array to be accessible to the full code that is inside the main...
3
by: ZMan | last post by:
The following code won't compile with gcc version 3.4.2 (mingw-special). How come? Error: cannot convert `char (*)' to `char**' /**********************************************************/...
11
by: Bob Yang | last post by:
Hi, I have this in C++ and I like to call it from c# to get the value but I fail. it will be good if you can give me some information. I tried it in VB.net it works but I use almost the same way as...
20
by: jason | last post by:
Hello, I'm a beginning C programmer and I have a question regarding arrays and finding the number of entries present within an array. If I pass an array of structures to a function, then...
8
by: S. | last post by:
Hi all, Can someone please help me with this? I have the following struct: typedef struct { char *name; int age; } Student;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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,...
0
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...
0
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...
0
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,...
0
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...

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.