473,387 Members | 1,585 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,387 software developers and data experts.

warning: excess elements in scalar initializer

hi !,

Following Code gives me following error's
warning: excess elements in scalar initializer
char *functionname = {

"abs", "sqrt", "sin", "cos", "atan", "log", "exp", "\0"

};

best regards
Helmut Januschka
Nov 14 '05 #1
5 23153
nrk
helmut januschka wrote:
hi !,

Following Code gives me following error's
warning: excess elements in scalar initializer
char *functionname = {

"abs", "sqrt", "sin", "cos", "atan", "log", "exp", "\0"

};

That's because your initializer is for an array of pointers to char, while
functionname is just a pointer to char (a scalar). What you want, probably
is:

char *functionname[] =
{ "abs", "sqrt", "sin", "cos", "atan", "log", "exp", "\0", };

-nrk.
best regards
Helmut Januschka


--
Remove devnull for email
Nov 14 '05 #2
In 'comp.lang.c', "helmut januschka" <kl****@chello.at> wrote:
warning: excess elements in scalar initializer

char *functionname = {

"abs", "sqrt", "sin", "cos", "atan", "log", "exp", "\0"

};


Sure, you want an array :

char const *functionname[] =
{
"abs", "sqrt", "sin", "cos", "atan", "log", "exp", NULL
};

(The NULL thing is probably useless...)

--
-ed- em**********@noos.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/
Nov 14 '05 #3
Emmanuel Delahaye wrote:
In 'comp.lang.c', "helmut januschka" <kl****@chello.at> wrote:

warning: excess elements in scalar initializer

char *functionname = {

"abs", "sqrt", "sin", "cos", "atan", "log", "exp", "\0"

};

Sure, you want an array :

char const *functionname[] =
{
"abs", "sqrt", "sin", "cos", "atan", "log", "exp", NULL
};

(The NULL thing is probably useless...)

Not at all. The NULL thing is more useful than the "\0" thing to be
sure. Consider..

for (i = 0; functionname[i] != NULL; ++i)
puts(functionname[i]);

...or..

for (i = 0; *functionname[i] != '\0'; ++i)
puts(functionname[i]);

I like the NULL treatment best.
--
Joe Wright mailto:jo********@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 14 '05 #4
In 'comp.lang.c', Joe Wright <jo********@comcast.net> wrote:
char const *functionname[] =
{
"abs", "sqrt", "sin", "cos", "atan", "log", "exp", NULL
};

(The NULL thing is probably useless...)

Not at all. The NULL thing is more useful than the "\0" thing to be
sure. Consider..

for (i = 0; functionname[i] != NULL; ++i)
puts(functionname[i]);

..or..

for (i = 0; *functionname[i] != '\0'; ++i)
puts(functionname[i]);

I like the NULL treatment best.


The old C-string vs Pascal-string discussion is back!

--
-ed- em**********@noos.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/
Nov 14 '05 #5
Emmanuel Delahaye wrote:
In 'comp.lang.c', Joe Wright <jo********@comcast.net> wrote:

char const *functionname[] =
{
"abs", "sqrt", "sin", "cos", "atan", "log", "exp", NULL
};

(The NULL thing is probably useless...)


Not at all. The NULL thing is more useful than the "\0" thing to be
sure. Consider..

for (i = 0; functionname[i] != NULL; ++i)
puts(functionname[i]);

..or..

for (i = 0; *functionname[i] != '\0'; ++i)
puts(functionname[i]);

I like the NULL treatment best.

The old C-string vs Pascal-string discussion is back!

I don't think my response did it but yours now does. The Pascal 'string'
has a leading unsigned char (0..255) to indicate the length of the
string. How would Pascal present a 300 character string?

--
Joe Wright mailto:jo********@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 14 '05 #6

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

Similar topics

12
by: Serve Laurijssen | last post by:
Is code like the following allowed? I am talking about the comma after the last function in the initializer. void f(void) {puts("f");} void g(void) {puts("g");} struct Funcs { void...
3
by: Old Wolf | last post by:
For the following code: struct S { char t; int flags; }; void func(void) {
4
by: bingfeng | last post by:
I have some codes generated by perl, in which initialize some huge struct,such as PARA TOS_network_spantree_set_0_para_0 = { "vlan", emNUM, NULL, "", "configuration on a designated vlan",...
13
by: Sam Steingold | last post by:
the following program does not compile with g++ 4.1.1: ==================================================== // $Id$ // $Source$ #include <stdint.h> #include <stdio.h> typedef struct {...
12
by: Pawel | last post by:
Hallo group members Could You tell hw to write this code in order not to get warning from subject: #include <iostream> using namespace std; using namespace __gnu_cxx; struct entry {
6
by: Daniel Rudy | last post by:
Hello Group. Please consider the following code: /* this table is used in the wipedevice routine */ static const struct wipe_t { uchar wte; /* wipe table entry */ } wipetable = {...
4
by: Thelma Roslyn Lubkin | last post by:
I use vector and matrix classes that I developed before they were otherwise easily available. They are template classes that should be able to use objects of other classes I've developed, e.g....
2
by: Thelma Lubkin | last post by:
I use my own matrix and vector classes. I wrote them before such things were generally available and I've stuck with them ever since. I've just added an Octonion class derived from the vectors...
9
by: dissectcode | last post by:
I couldn't find an anser on google...The following code is a tiny made-up example showing the problem I am looking at, at work. I have a struct: struct door_t { BOOL color; BOOL size; ...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
jinu1996
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 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.