const struct
{
float a0;
float a1;
float a2;
}A_coeffs[SECTIONS];
i am confused to declare the value for this structure correct me
thanq
i have declared this there is compiler error
A_coeffs[]=
{
{1.254285,2.508570,1.254285},
{1.254285,2.508570,1.254285},
{1.254285,2.508570,1.254285},
}; 11 1149
This will assign value as
follows
a_coeffs[0].a0=1.254285,
a_coeffs[0].a1=2.508570,
a_coeffs[0].a2=1.254285,
a_coeffs[1].a0=1.254285,
a_coeffs[1].a1=1.508570,
a_coeffs[1].a2=1.254285,
like this it will go on
In article <11**********************@g44g2000cwa.googlegroups .com>, siva
<si*********@gmail.com> writes const struct { float a0; float a1; float a2; }A_coeffs[SECTIONS]; A_coeffs[]= { {1.254285,2.508570,1.254285}, {1.254285,2.508570,1.254285}, {1.254285,2.508570,1.254285}, };
Nearly.
#define SECTIONS 3
const struct
{
float a0;
float a1;
float a2;
}A_coeffs[SECTIONS]=
{
{1.254285,2.508570,1.254285},
{1.254285,2.508570,1.254285},
{1.254285,2.508570,1.254285},
};
thanq
u have give me good solution
<snip> i am confused to declare the value for this structure correct me thanq
i have declared this there is compiler error A_coeffs[]=
<snip> };
Please quote the compiler error.
It helps in debugging.
Regards,
Frodo
siva wrote: const struct { float a0; float a1; float a2; }A_coeffs[SECTIONS];
Here you have declared it as being const, which means you are not
allowed to write to it.
i am confused to declare the value for this structure correct me thanq
i have declared this there is compiler error A_coeffs[]= { {1.254285,2.508570,1.254285}, {1.254285,2.508570,1.254285}, {1.254285,2.508570,1.254285}, };
Here you try to write to it (which is not allowed) and you are also
trying to write the hole array, which is not allowed anyway.
Assuming these really are constant coefficients you want something like:
const struct
{
float a0;
float a1;
float a2;
} A_coeffs[] = {
{1.254285,2.508570,1.254285},
{1.254285,2.508570,1.254285},
{1.254285,2.508570,1.254285},
};
#define SECTIONS ((sizeof A_coeffs) / (sizeof A_coeffs[0]))
and get rid of your current definition of SECTIONS.
This is pretty basic stuff so you probably need to reread the sections
your text book has on arrays, initialisers, const and sizeof.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
In article <68************@news.flash-gordon.me.uk>, Flash Gordon
<sp**@flash-gordon.me.uk> writes #define SECTIONS ((sizeof A_coeffs) / (sizeof A_coeffs[0]))
and get rid of your current definition of SECTIONS.
Not necessarily.
In many cases #define'ing SECTIONS in advance of the declaration of the
array would be preferable because it might be calculated based upon
something else, sourced from another file, or simply more obvious to the
developer that way, and the point of then using it in the declaration of
the array is to stop the programmer forgetting to then initialise all
the elements.
Stephen wrote: In article <68************@news.flash-gordon.me.uk>, Flash Gordon <sp**@flash-gordon.me.uk> writes
#define SECTIONS ((sizeof A_coeffs) / (sizeof A_coeffs[0]))
and get rid of your current definition of SECTIONS.
Not necessarily.
In many cases #define'ing SECTIONS in advance of the declaration of the array would be preferable because it might be calculated based upon something else, sourced from another file, or simply more obvious to the developer that way, and the point of then using it in the declaration of the array is to stop the programmer forgetting to then initialise all the elements.
It does not necessarily stop the programmer from forgetting to
initialise all the elements, because there is not requirement for the
compiler to complain at you for forgetting to initialise all of the
elements.
I'm not saying that there is never a good reason to define the size in
some other way, but for a const array (which it was in this case) I
believe that what I suggested is generally better.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
"Flash Gordon" <sp**@flash-gordon.me.uk> wrote in message
news:qv************@news.flash-gordon.me.uk... Stephen wrote: In article <68************@news.flash-gordon.me.uk>, Flash Gordon <sp**@flash-gordon.me.uk> writes
#define SECTIONS ((sizeof A_coeffs) / (sizeof A_coeffs[0]))
and get rid of your current definition of SECTIONS.
Not necessarily.
In many cases #define'ing SECTIONS in advance of the declaration of the array would be preferable because it might be calculated based upon something else, sourced from another file, or simply more obvious to the developer that way, and the point of then using it in the declaration of the array is to stop the programmer forgetting to then initialise all the elements.
It does not necessarily stop the programmer from forgetting to initialise all the elements, because there is not requirement for the compiler to complain at you for forgetting to initialise all of the elements.
With an array, if you initialize at least one element,
they all get initialized (but perhaps not to the desired values :-))
-Mike
Mike Wahler wrote: "Flash Gordon" <sp**@flash-gordon.me.uk> wrote in message news:qv************@news.flash-gordon.me.uk...
Stephen wrote:
In article <68************@news.flash-gordon.me.uk>, Flash Gordon <sp**@flash-gordon.me.uk> writes
#define SECTIONS ((sizeof A_coeffs) / (sizeof A_coeffs[0]))
and get rid of your current definition of SECTIONS.
Not necessarily.
In many cases #define'ing SECTIONS in advance of the declaration of the array would be preferable because it might be calculated based upon something else, sourced from another file, or simply more obvious to the developer that way, and the point of then using it in the declaration of the array is to stop the programmer forgetting to then initialise all the elements.
It does not necessarily stop the programmer from forgetting to initialise all the elements, because there is not requirement for the compiler to complain at you for forgetting to initialise all of the elements.
With an array, if you initialize at least one element, they all get initialized (but perhaps not to the desired values :-))
This, indeed, was what I meant :-)
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
In article <de************@news.flash-gordon.me.uk>, Flash Gordon
<sp**@flash-gordon.me.uk> writes Mike Wahler wrote: "Flash Gordon" <sp**@flash-gordon.me.uk> wrote in message news:qv************@news.flash-gordon.me.uk...
Stephen wrote:
In article <68************@news.flash-gordon.me.uk>, Flash Gordon <sp**@flash-gordon.me.uk> writes
>#define SECTIONS ((sizeof A_coeffs) / (sizeof A_coeffs[0])) > >and get rid of your current definition of SECTIONS.
Not necessarily.
In many cases #define'ing SECTIONS in advance of the declaration of the array would be preferable because it might be calculated based upon something else, sourced from another file, or simply more obvious to the developer that way, and the point of then using it in the declaration of the array is to stop the programmer forgetting to then initialise all the elements.
It does not necessarily stop the programmer from forgetting to initialise all the elements, because there is not requirement for the compiler to complain at you for forgetting to initialise all of the elements.
With an array, if you initialize at least one element, they all get initialized (but perhaps not to the desired values :-))
This, indeed, was what I meant :-)
I see. I'll need to bear this in mind for the future, but I'm reasonably
sure most of the 5 or so C compilers I make a living from complain if
the number of elements in the aggregate assignment doesn't match the
size of the array. Will do some testing, if I ever get a spare moment...
Stephen wrote: In article <de************@news.flash-gordon.me.uk>, Flash Gordon <sp**@flash-gordon.me.uk> writes
Mike Wahler wrote:
<snip> With an array, if you initialize at least one element, they all get initialized (but perhaps not to the desired values :-))
This, indeed, was what I meant :-)
I see. I'll need to bear this in mind for the future, but I'm reasonably sure most of the 5 or so C compilers I make a living from complain if the number of elements in the aggregate assignment doesn't match the size of the array. Will do some testing, if I ever get a spare moment...
It's actually a very useful feature, since it means if you want to
create an automatic structure initialised to zeros (perhaps it contains
counts, sums, averages and pointers) you can do
complex_type_t somevar = {0};
Far easier than either fully specifying it or looping over it.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Andy Sutorius |
last post by:
Has anyone successfully created a Hello World program without using Visual
Studio.NET? If so, what IDE did you use and what namespaces did you import?
Thanks!
Andy Sutorius
|
by: Tim Judd |
last post by:
I must not be grasping anything here.
Just a simple application, as follows (as any first-program is...)
----
#include <iostream.h>
int main() {
cout <<"hello world";
return 0;
|
by: Matthew |
last post by:
How would I go about creating a simple "hello world" program that will
run in Unix. I am using MS Visual C++.
|
by: jrefactors |
last post by:
If the C programs have UNIX system calls such as fork(), alarm(),
etc.., we should call it UNIX programs, not traditional C programs?
We couldn't compile the programs with system calls using VC++...
|
by: Santanu Chatterjee |
last post by:
Hello all,
I would like to know how an OS makes a computer boot up.
For that, as a start I would like to see an e_ample (read the
underscore as the letter before y, as the keyboard here is...
|
by: arnuld |
last post by:
i am learning C and doing the exercise 1-1 of K&R2, where K&R ask to
remove some parts of programme and experiment with error, so here i
go:
#include <stdio.h>
int main () {
printf('hello...
|
by: theokok2000 |
last post by:
i am new-comer in c++ and programing general.I have download borland
turbo c++ and i try to run "hello world" but nothing!!! does anyone
knows the procedure to run and "see" the results of simple...
|
by: boxfish |
last post by:
Happy Hello World Day to the C/C++ forum! Today is the day to write cryptic "Hello World" programs and say hello to at least ten people:
#include <iostream>
using namespace std;
int main() {
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
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: 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: 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: 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...
|
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...
| |