Hello all,
After reading through chapter 6 of the faq I must admit
I'm a bit confused :-).
What I am trying to do can be explained with the following
three sample files:
var.c:
float a[2][2] = {{1.0f, 2.0f},{3.0f, 4.0f}};
var.h:
#ifndef var_h
#define var_h
extern float a**;
#endif
test.c
#include "var.h"
#include <stdio.h>
int main() {
printf("a[0][0] = %f\n", a[0][0]);
return(0);
}
This doesn't appear to be working though since the compiler (gcc)
reports "'a' undeclared". I know from the faq that arrays and
pointers are not the same but after having tried declaring 'a' as
'extern float* a[];' and 'extern float a[][];' I've found that
the only thing which compiles is 'extern float* a[];' but this
only gives me an array of pointers to unallocated memory.
How do I do the two-dimensional thing?
Regards, Jimmy 8 2498
Jimmy Petersen <ji*@dtv.dk> scribbled the following: Hello all,
After reading through chapter 6 of the faq I must admit I'm a bit confused :-).
What I am trying to do can be explained with the following three sample files:
var.c: float a[2][2] = {{1.0f, 2.0f},{3.0f, 4.0f}};
var.h: #ifndef var_h #define var_h
extern float a**;
a is declared as the wrong type here. Even though T[] and T* are
assignment-compatible types, T[][] and T** are not. Chris Torek can
explain this in detail. You should declare this as:
extern float (*a)[2];
or:
extern float a[2][2];
#endif
test.c #include "var.h" #include <stdio.h>
int main() { printf("a[0][0] = %f\n", a[0][0]); return(0); }
This doesn't appear to be working though since the compiler (gcc) reports "'a' undeclared". I know from the faq that arrays and pointers are not the same but after having tried declaring 'a' as 'extern float* a[];' and 'extern float a[][];' I've found that the only thing which compiles is 'extern float* a[];' but this only gives me an array of pointers to unallocated memory.
How do I do the two-dimensional thing?
Try declaring a as "extern float (*a)[];". The way you compiled it, it
was an array of pointers - you need a pointer to an array.
--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Remember: There are only three kinds of people - those who can count and those
who can't."
- Vampyra
Jimmy Petersen <ji*@dtv.dk> scribbled the following: Hello all,
After reading through chapter 6 of the faq I must admit I'm a bit confused :-).
What I am trying to do can be explained with the following three sample files:
var.c: float a[2][2] = {{1.0f, 2.0f},{3.0f, 4.0f}};
var.h: #ifndef var_h #define var_h
extern float a**;
a is declared as the wrong type here. Even though T[] and T* are
assignment-compatible types, T[][] and T** are not. Chris Torek can
explain this in detail. You should declare this as:
extern float (*a)[2];
or:
extern float a[2][2];
#endif
test.c #include "var.h" #include <stdio.h>
int main() { printf("a[0][0] = %f\n", a[0][0]); return(0); }
This doesn't appear to be working though since the compiler (gcc) reports "'a' undeclared". I know from the faq that arrays and pointers are not the same but after having tried declaring 'a' as 'extern float* a[];' and 'extern float a[][];' I've found that the only thing which compiles is 'extern float* a[];' but this only gives me an array of pointers to unallocated memory.
How do I do the two-dimensional thing?
Try declaring a as "extern float (*a)[];". The way you compiled it, it
was an array of pointers - you need a pointer to an array.
--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Remember: There are only three kinds of people - those who can count and those
who can't."
- Vampyra
Jimmy Petersen wrote: Hello all,
After reading through chapter 6 of the faq I must admit I'm a bit confused :-).
What I am trying to do can be explained with the following three sample files:
var.c: float a[2][2] = {{1.0f, 2.0f},{3.0f, 4.0f}};
var.h: #ifndef var_h #define var_h
extern float a**;
#endif
test.c #include "var.h" #include <stdio.h>
int main() { printf("a[0][0] = %f\n", a[0][0]); return(0); }
This doesn't appear to be working though since the compiler (gcc) reports "'a' undeclared". I know from the faq that arrays and pointers are not the same but after having tried declaring 'a' as 'extern float* a[];' and 'extern float a[][];' I've found that the only thing which compiles is 'extern float* a[];' but this only gives me an array of pointers to unallocated memory.
How do I do the two-dimensional thing?
Change, in var.h
extern float **a;
to
extern float a[2][2];
--
Al Bowers
Tampa, Fl USA
mailto: xa******@myrapi dsys.com (remove the x to send email) http://www.geocities.com/abowers822/
Jimmy Petersen wrote: Hello all,
After reading through chapter 6 of the faq I must admit I'm a bit confused :-).
What I am trying to do can be explained with the following three sample files:
var.c: float a[2][2] = {{1.0f, 2.0f},{3.0f, 4.0f}};
var.h: #ifndef var_h #define var_h
extern float a**;
#endif
test.c #include "var.h" #include <stdio.h>
int main() { printf("a[0][0] = %f\n", a[0][0]); return(0); }
This doesn't appear to be working though since the compiler (gcc) reports "'a' undeclared". I know from the faq that arrays and pointers are not the same but after having tried declaring 'a' as 'extern float* a[];' and 'extern float a[][];' I've found that the only thing which compiles is 'extern float* a[];' but this only gives me an array of pointers to unallocated memory.
How do I do the two-dimensional thing?
Change, in var.h
extern float **a;
to
extern float a[2][2];
--
Al Bowers
Tampa, Fl USA
mailto: xa******@myrapi dsys.com (remove the x to send email) http://www.geocities.com/abowers822/
Joona I Palaste wrote: Jimmy Petersen <ji*@dtv.dk> scribbled the following: var.c: float a[2][2] = {{1.0f, 2.0f},{3.0f, 4.0f}}; var.h: #ifndef var_h #define var_h
extern float a**;
This is a syntax error, by the way. You mean:
extern float **a;
(which is still semantically wrong, though syntactically correct).
a is declared as the wrong type here. Even though T[] and T* are assignment-compatible types, T[][] and T** are not. Chris Torek can explain this in detail. You should declare this as: extern float (*a)[2]; or: extern float a[2][2];
Only the second is a valid declaration for the array in the source
file. "Assignment-compatible" is irrelevant here. See section 6 of
the FAQ.
I know from the faq that arrays and pointers are not the same but after having tried declaring 'a' as 'extern float* a[];' and 'extern float a[][];' I've found that the only thing which compiles is 'extern float* a[];' but this only gives me an array of pointers to unallocated memory.
How do I do the two-dimensional thing?
extern float a[2][2];
Try declaring a as "extern float (*a)[];". The way you compiled it, it was an array of pointers - you need a pointer to an array.
No, he needs an array of arrays.
Jeremy.
Joona I Palaste wrote: Jimmy Petersen <ji*@dtv.dk> scribbled the following: var.c: float a[2][2] = {{1.0f, 2.0f},{3.0f, 4.0f}}; var.h: #ifndef var_h #define var_h
extern float a**;
This is a syntax error, by the way. You mean:
extern float **a;
(which is still semantically wrong, though syntactically correct).
a is declared as the wrong type here. Even though T[] and T* are assignment-compatible types, T[][] and T** are not. Chris Torek can explain this in detail. You should declare this as: extern float (*a)[2]; or: extern float a[2][2];
Only the second is a valid declaration for the array in the source
file. "Assignment-compatible" is irrelevant here. See section 6 of
the FAQ.
I know from the faq that arrays and pointers are not the same but after having tried declaring 'a' as 'extern float* a[];' and 'extern float a[][];' I've found that the only thing which compiles is 'extern float* a[];' but this only gives me an array of pointers to unallocated memory.
How do I do the two-dimensional thing?
extern float a[2][2];
Try declaring a as "extern float (*a)[];". The way you compiled it, it was an array of pointers - you need a pointer to an array.
No, he needs an array of arrays.
Jeremy.
In 'comp.lang.c', "Jimmy Petersen" <ji*@dtv.dk> wrote: After reading through chapter 6 of the faq I must admit I'm a bit confused :-).
What I am trying to do can be explained with the following three sample files:
var.c:
For code sanity, add this:
#include "var.h"
float a[2][2] = {{1.0f, 2.0f},{3.0f, 4.0f}};
var.h: #ifndef var_h #define var_h
extern float a**;
This is wrong. You want:
extern float a[2][2];
#endif
test.c #include "var.h" #include <stdio.h>
int main() { printf("a[0][0] = %f\n", a[0][0]);
Don't feel happy with a '[0][0]' test. Better to try with values that are not
0 :
printf("a[1][1] = %f\n", a[1][1]); /* expected : 4.0000 */
or better, to traverse the whole thing.
return(0); }
--
-ed- em**********@no os.fr [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=cpp
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
In 'comp.lang.c', "Jimmy Petersen" <ji*@dtv.dk> wrote: After reading through chapter 6 of the faq I must admit I'm a bit confused :-).
What I am trying to do can be explained with the following three sample files:
var.c:
For code sanity, add this:
#include "var.h"
float a[2][2] = {{1.0f, 2.0f},{3.0f, 4.0f}};
var.h: #ifndef var_h #define var_h
extern float a**;
This is wrong. You want:
extern float a[2][2];
#endif
test.c #include "var.h" #include <stdio.h>
int main() { printf("a[0][0] = %f\n", a[0][0]);
Don't feel happy with a '[0][0]' test. Better to try with values that are not
0 :
printf("a[1][1] = %f\n", a[1][1]); /* expected : 4.0000 */
or better, to traverse the whole thing.
return(0); }
--
-ed- em**********@no os.fr [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=cpp
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Rob Tweed |
last post by:
Probably a simple question but I can't find the answer anyway.
Specifically, is it possible to copy a multidimensional array into the
$_SESSION array - ie a deep clone of all keys and data?
I naively assumed that
$_SESSION = $myArray ;
would work but it doesn't appear to work. Is there a single function
|
by: Charles Banas |
last post by:
i've got an interesting peice of code i'm maintaining, and i'd like to
get some opinions and comments on it, hopefully so i can gain some
sort of insight as to why this works.
at the top of the function (which was translated from Fortran code),
among other heinous and numerous declarations, is this bit:
static float bbuff;
static int bkey;
static int buse;
|
by: Mark Smith |
last post by:
I'm trying to copy data from a 1D array to a 2D array.
The obvious thing doesn't work:
int twoDee = new int;
int oneDee = new int { 1, 2 };
Array.Copy(oneDee, 2, twoDee, 2, 2);
This causes a RankException. But the MSDN documentation says:
When copying between multidimensional arrays, the array
|
by: chris |
last post by:
Hi there,
I created a Multidimensional array of labels
Label lblMultiArray = new Label { {Label3, LblThuTotal},
{Label4,LblFriTotal} };
Now I would like to compare the values in the array, comparing the text in
Label3 and LblThuTotal and the text in Label4 and LblFriTotal.
|
by: |
last post by:
I'm fairly new to ASP and must admit its proving a lot more unnecessarily
complicated than the other languages I know. I feel this is because there
aren't many good official resources out there to help do the most basic
things.
One of the "basic" things I haven't been able to find out how to do is how
to delete an item from a multidimensional array object and resize it
afterwards.
It seems so easy to conceive of the code to delete...
| |
by: xhunga |
last post by:
I have try a new version of my work.
I have put the sizes of the matrix into the matrix.
A = number of rows
A = number of columns
The first element of the matrix is A
instead of A.
You can not use the row 0, and the column 0.
|
by: Chuy08 |
last post by:
If I have a multidimensional array like the following:
Array
$records =Array
0 = 30 year, 6.0;
1 = 30 year, 6.0;
2 = Pay Option, 1.0;
3 = Pay Option, 1.0;
How could I flatten this to achieve an array that only has unique Product
|
by: LittleCake |
last post by:
Hi All,
I have a multidimensional array where each sub-array contains just two
entries, which indicates a relationship between those two entries. for
example the first sub-array:
=Array
(
=30
=31
)
|
by: Jezternz |
last post by:
First of all I am open to any suggestions and advice. If a javscript multidimensional array is a bad way to do this please say so. I considered XML but I wondered if this would be a bad idea as it would be slower for jsp to handel.
Okay here is an example of my multidimensional array (only part of it)(bottom of the post). It works fine I can call any of the 3rd dimension without trouble.
Now How would I go about printing something like...
|
by: Slain |
last post by:
I need to convert a an array to a multidimensional one. Since I need
to wrok with existing code, I need to modify a declaration which looks
like this
In the .h file
int *x;
in a initialize function:
x = new int;
|
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...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |