By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,331 Members | 1,428 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,331 IT Pros & Developers. It's quick & easy.

How can I get rid of this C4047 Indirection warning?

P: n/a
I like to keep warnings to a minimum and am find this one cropping up a
lot.

struct auction_bargains bargainList[LIST_SIZE];
struct auction_bargains *pBargainList = &bargainList;

I am creating an array of a fixed size and pBargainList allows me to
access it from any function.

C:\Documents and Settings\patrick\My
Documents\projects\DayTrader\FindBargains.c(13) : warning C4047:
'initializing' : 'struct auction_bargains *' differs in levels of
indirection from 'struct auction_bargains (*)[5]'

Should I worry?

Sep 27 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
pkirk25 wrote:
I like to keep warnings to a minimum and am find this one cropping up a
lot.

struct auction_bargains bargainList[LIST_SIZE];
struct auction_bargains *pBargainList = &bargainList;

I am creating an array of a fixed size and pBargainList allows me to
access it from any function.

C:\Documents and Settings\patrick\My
Documents\projects\DayTrader\FindBargains.c(13) : warning C4047:
'initializing' : 'struct auction_bargains *' differs in levels of
indirection from 'struct auction_bargains (*)[5]'

Should I worry?
Yes.

Perhaps you want to point it at the first element in the bargainList
array. That would be the address of its first element(which is at
index 0)

struct auction_bargains *pBargainList = &bargainList[0];

This is the same as
struct auction_bargains *pBargainList = bargainList;
Sep 27 '06 #2

P: n/a

pkirk25 wrote:
I like to keep warnings to a minimum and am find this one cropping up a
lot.

struct auction_bargains bargainList[LIST_SIZE];
struct auction_bargains *pBargainList = &bargainList;
change above code to following code .

struct auction_bargains bargainList[LIST_SIZE];
struct auction_bargains *pBargainList = bargainList;

Sep 27 '06 #3

P: n/a
"pkirk25" <pa*****@kirks.netwrites:
I like to keep warnings to a minimum and am find this one cropping up a
lot.

struct auction_bargains bargainList[LIST_SIZE];
struct auction_bargains *pBargainList = &bargainList;

I am creating an array of a fixed size and pBargainList allows me to
access it from any function.

C:\Documents and Settings\patrick\My
Documents\projects\DayTrader\FindBargains.c(13) : warning C4047:
'initializing' : 'struct auction_bargains *' differs in levels of
indirection from 'struct auction_bargains (*)[5]'

Should I worry?
Either

struct auction_bargains *pBargainList = &bargainList[0];

or

struct auction_bargains *pBargainList = bargainList;

gives you a pointer to the first element of the table. What &bargainList
gives you a pointer to the whole table, and the compiler rightly complain.

Yours,

--
Jean-Marc
Sep 27 '06 #4

P: n/a
pkirk25 said:
I like to keep warnings to a minimum and am find this one cropping up a
lot.

struct auction_bargains bargainList[LIST_SIZE];
struct auction_bargains *pBargainList = &bargainList;
Remove the &, or change pBargainList's type to struct (auction_bargains
*)[LIST_SIZE]. One or the other, but not both. Which you choose depends on
factors which you have not told us about.
>
I am creating an array of a fixed size and pBargainList allows me to
access it from any function.

C:\Documents and Settings\patrick\My
Documents\projects\DayTrader\FindBargains.c(13) : warning C4047:
'initializing' : 'struct auction_bargains *' differs in levels of
indirection from 'struct auction_bargains (*)[5]'

Should I worry?
Yes. Alternatively, remove the &, or change the type as I indicated.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 27 '06 #5

P: n/a
pkirk25 wrote:
I like to keep warnings to a minimum and am find this one cropping up a
lot.

struct auction_bargains bargainList[LIST_SIZE];
struct auction_bargains *pBargainList = &bargainList;

I am creating an array of a fixed size and pBargainList allows me to
access it from any function.
In this snipped, `pBargainList` and `bargainList` have equally global
(which is to say, horribly excessively exposed) access.

[Style query: why camelCase the variable names but not the struct
names?]
C:\Documents and Settings\patrick\My
Documents\projects\DayTrader\FindBargains.c(13) : warning C4047:
'initializing' : 'struct auction_bargains *' differs in levels of
indirection from 'struct auction_bargains (*)[5]'

Should I worry?
No, worrying is pointless - easier to fix the code. `pBargainList`
should be initialised with a pointer-to-struct-auction_bargains,
not a pointer-to-an-array-of-LIST_SIZE-struct-auction_bargains.

If you want to keep the type of `pBargainList`, write whichever
of

struct auction_bargains *pBargainList = bargainList;
struct auction_bargains *pBargainList = &bargainList[0];

fits your stylistic preferences.

Arrays are not pointers. Pointers are not arrays. The address
of an array isn't the same thing as the address of its first
element. See the FAQ for a more detailed discussion.

--
Chris "falling further in" Dollin
RIP John M. Ford (April 10, 1957 -- September 24, 2006)

Sep 27 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.