Hello,
say I've a code:
....
struct device_defs {
unsigned int vendor;
unsigned int dev;
unsigned int mask;
unsigned long data;
};
static struct device_defs device_defs_tbl[] =
{
{ 0x0000, 0x0011, 0x0000, 0x0000, 0, 0, 0},
{ }
}
int main(void)
{
...
return 0;
}
What's correct way to initialize 'device_defs_tbl'? Running
'gcc -std=c99 -W -Wall' or '-ansi' both result in warnings:
t.c:13: warning: missing initializer
t.c:13: warning: (near initialization for `device_defs_tbl[1].vendor')
Thank you.
With best regards, Roman Mashak. E-mail: mr*@tusur.ru 4 2510
Roman Mashak wrote:
>
Hello,
say I've a code:
...
struct device_defs {
unsigned int vendor;
unsigned int dev;
unsigned int mask;
unsigned long data;
};
static struct device_defs device_defs_tbl[] =
{
{ 0x0000, 0x0011, 0x0000, 0x0000, 0, 0, 0},
{ }
}
int main(void)
{
...
return 0;
}
What's correct way to initialize 'device_defs_tbl'?
static struct device_defs device_defs_tbl[] = {
{ 0x0000, 0x0011, 0x0000, 0x0000},
{ 0, 0, 0, 0}
};
--
pete
Hello, pete!
You wrote on Thu, 04 Jan 2007 03:52:07 GMT:
??>int main(void)
??>{
??> ...
??> return 0;
??>}
??>>
??>What's correct way to initialize 'device_defs_tbl'?
pstatic struct device_defs device_defs_tbl[] = {
p { 0x0000, 0x0011, 0x0000, 0x0000},
p { 0, 0, 0, 0}
p};
I missed that. Thanks a lot. Seems like GNU extensions allow initializations
of only the first member of structure, as I've seen it in linux code base a
lot.
With best regards, Roman Mashak. E-mail: mr*@tusur.ru
Roman Mashak said:
Hello,
say I've a code:
...
struct device_defs {
unsigned int vendor;
unsigned int dev;
unsigned int mask;
unsigned long data;
};
static struct device_defs device_defs_tbl[] =
{
{ 0x0000, 0x0011, 0x0000, 0x0000, 0, 0, 0},
{ }
}
Yuk.
You could do this:
static struct device_defs device_defs_tbl[] =
{
{0, 0x11},
{0}
};
and take the hit on the warning. gcc is required by the C Standard to
initialise the table properly anyway for no fewer than two reasons
(firstly, it's static, and secondly, it's partly initialised).
What's correct way to initialize 'device_defs_tbl'? Running
'gcc -std=c99 -W -Wall' or '-ansi' both result in warnings:
Unfortunately, the C Standard allows implementations to spout any old
rubbish as long as they diagnose syntax errors and constraint violations
and as long as they correctly translate correct programs. What you've
discovered is that gcc is perfectly capable of producing silly and
misleading warning messages for perfectly correct code whose behaviour is
guaranteed by the Standard.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk
email: rjh at the above domain, - www.
On Thu, 4 Jan 2007 12:05:51 +0900, "Roman Mashak" <mr*@tusur.ru>
wrote:
>Hello,
say I've a code: ... struct device_defs {
unsigned int vendor;
unsigned int dev;
unsigned int mask;
unsigned long data; };
You have a struct type with 4 members.
> static struct device_defs device_defs_tbl[] =
You attempt to define an array of this struct type
>{
{ 0x0000, 0x0011, 0x0000, 0x0000, 0, 0, 0},
For the first element of the array, you provide 7 initializers. Why?
{ }
You apparently want the array to have two elements. Is that correct.
>}
int main(void) {
...
return 0; }
What's correct way to initialize 'device_defs_tbl'? Running 'gcc -std=c99 -W -Wall' or '-ansi' both result in warnings:
There are at least two options
static struct device_defs device_defs_tbl[2] =
{
{ 0x0000, 0x0011, 0x0000, 0x0000 }
}
or the possibly more flexible
static struct device_defs device_defs_tbl[] =
{
{ 0x0000, 0x0011, 0x0000, 0x0000 }
{ 0 }
}
You can remove the last two 0x0000 initializers in either case since
the standard requires the uninitialized portions of an initialized
aggregate object to be automatically initialized to 0, 0.0,or NULL as
appropriate.
Remove del for email This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Alexander Stippler |
last post by:
Hi,
I wonder about the behaviour of como and icc on some very simple program. I
thought initializing members of classes, which are of class type, would be
'direct initialized' (as the standard...
|
by: Todd Nathan |
last post by:
Hi. have this code and compiler problem. GCC 2.95.3, BeOS, error
"initializer element is not constant"
#ifdef FILEIO
{ static struct {
char *sfn;
FILE *sfd;
} stdfiles = {
|
by: Old Wolf |
last post by:
For the following code:
struct S
{
char t;
int flags;
};
void func(void)
{
|
by: Player |
last post by:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello all.
I am in the process of teaching myself C# and I think I am doing OK.
I have learnt how to how to call the right constructor of a...
|
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 {
|
by: Ham Pastrami |
last post by:
class Point {
public:
const int x, y;
Point(int x, int y);
}
Point::Point(int x, int y) : x(x), y(y)
{
}
|
by: Marvin Barley |
last post by:
I have a class that throws exceptions in new initializer, and a static
array of objects of this type.
When something is wrong in initialization, CGI program crashes
miserably. Debugging shows...
|
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;
...
|
by: yookoala |
last post by:
Hello,
I'm compiling something with GCC 4.4.1
Here I got some error from make.
It says:
This is the content of line 233 to 291:
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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,...
|
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: 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...
| |