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

How can I get rid of this C4047 Indirection warning?

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
5 6860
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

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
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: robin.pain | last post by:
I was looking for GBS's phonetic dictionary when I came across an American who was having problems with it... of course, it can never work for... Geordies, Irish, Brummies, Strynes, South ifrrikuns...
0
by: Harlan Messinger | last post by:
What's the purpose of the levels of indirection that are used in the latest W3C DTDs? I'm talking, for example, about the replacement of old-style, hard-coded <!ELEMENT TABLE - - (CAPTION?,...
10
by: isxyos | last post by:
Hello, It's just a warning, but can anybody explain to me what this warning is: warning C4047: '=' : 'unsigned int ' differs in levels of indirection from 'void *' #include <stdio.h> void...
39
by: gtippery | last post by:
Newbie-ish questions - I've been away from C for a _long_ time. It seems to me that there ought to be easier (or at least shorter) ways to do what this does. It does compile & run for me (with...
19
by: santosh | last post by:
Hi all, In the following program I allocate a block of pointers to type char, initialised to zero. I then point each of those pointers to a block of allocated memory of fixed size (33 bytes). A...
16
by: cody | last post by:
Shouldn't if (this!=null) generate a compiler warning? in fact, it does not.
5
by: Marty | last post by:
I am wondering what is the difference in the placement between the 2 uses of the indirection operator? Or is there a difference? AcDbBlockTable *pBlockTable = NULL; AcDbDatabase* pDB =...
4
by: Sam Tan | last post by:
Hello got two warning when compiling , the .exe file works fine with these warning but i prefer to get rid of them :) if anyone can point me to a general website for indirection warnings that...
92
by: Heinrich Pumpernickel | last post by:
what does this warning mean ? #include <stdio.h> int main() { long l = 100; printf("l is %li\n", l * 10L);
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
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,...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.