473,405 Members | 2,379 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,405 software developers and data experts.

Hello i am new to this C programs

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},
};

Nov 15 '05 #1
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

Nov 15 '05 #2
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},
};

Nov 15 '05 #3
thanq

u have give me good solution

Nov 15 '05 #4

<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

Nov 15 '05 #5
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.
Nov 15 '05 #6
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.
Nov 15 '05 #7
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.
Nov 15 '05 #8

"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
Nov 15 '05 #9
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.
Nov 15 '05 #10
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...
Nov 15 '05 #11
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.
Nov 15 '05 #12

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

Similar topics

24
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
17
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;
6
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++.
12
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++...
26
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...
4
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...
1
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...
2
boxfish
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() { ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
1
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...
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
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
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,...
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
tracyyun
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...
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.