![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
||||
|
||||
Warning C4267: '=' : conversion from 'size_t' to 'unsigned int', possible loss of...I'm a bit stumped by a compiler warning that arises from this code:
CPP / C++ / C Code:
I get the following warning: .\CTNode.cpp(25) : warning C4267: '=' : conversion from 'size_t' to 'unsigned int', possible loss of data The warning is referring to the single line in the body of the for loop. I understand exactly what the warning means, but I can't figure out why I'm getting it here, since dereferencing the iterator should be returning an unsigned int. I've verified that the warning is a result of dereferencing the iterator; if I add the line unsigned int x = *iter; to the body of the for loop, it triggers a similar warning. The code works perfectly well, but I'm a bit obsessive about getting a clean compile. Any ideas? Neither I nor the coworkers I've asked can figure this one out. I'm using MSVC 2008 under 64-bit Windows 7 Professional. P.S. Here's the header for the CTNode class, just in case it's useful: CPP / C++ / C Code:
__________________
www.blake-foster.com Last edited by Blake : 28-Jul-2010 at 13:06.
|
||||
|
#2
|
|||
|
|||
Re: Bizzare compiler warning dereferencing list<unsigned int>::const_iteratorQuote:
Since I don't have your software and operating system, I can't test this: Make a simple program that prints out sizeof(size_t) and sizeof(unsigned int); Regards, Dave __________________
Sometimes I just can't help myself... |
|
#3
|
||||
|
||||
Re: Bizzare compiler warning dereferencing list<unsigned int>::const_iteratorI've confirmed that size_t and unsigned int are both 32 bits on my system. The question that really has me puzzled is why dereferencing the iterator returns an element of type size_t to begin with.
This generates a similar warning: CPP / C++ / C Code:
The warning (in this case) is: .\CTNode.cpp(25) : warning C4267: 'initializing' : conversion from 'size_t' to 'unsigned int', possible loss of data Weirder still, this does not generate a warning: CPP / C++ / C Code:
I've been a programmer for long enough to become very wary about blaming bugs in the compiler, but this one has my suspicious. Thanks! __________________
www.blake-foster.com |
|
#4
|
||||
|
||||
Re: Bizzare compiler warning dereferencing list<unsigned int>::const_iteratorhello Blake,
I found this at MSDN, but not sure how helpful their explanation is though. EDIT: Also, I believe that having the 'Detect 64-bit portability issues' will generate this warning. Perhaps disabling this check might silence the warning, if 64-bit porting is not a concern. __________________
Use the force...read the source!! WYCIWYG -- what you code is what you get! Last edited by TurboPT : 28-Jul-2010 at 16:19.
|
|
#5
|
||||
|
||||
Re: Bizzare compiler warning dereferencing list<unsigned int>::const_iteratorThanks! Disabling 'Detect 64-bit portability issues' made the warning go away. However, I still can't figure out why dereferencing a list<unsigned int>::const_iterator is triggering that warning.
__________________
www.blake-foster.com |
|
#6
|
||||
|
||||
Re: Bizzare compiler warning dereferencing list<unsigned int>::const_iteratorQuote:
(that is why I said I'm not sure how helpful [or clear?] their explanation would be...) Quote:
__________________
Use the force...read the source!! WYCIWYG -- what you code is what you get! |
|
#7
|
||||
|
||||
Re: Bizzare compiler warning dereferencing list<unsigned int>::const_iteratorI understand why the code in the MSDN example triggers a warning. I'm just not seeing how that relates to my code. Dereferencing a list<unsigned int>::const_iterator should return an unsigned int, not a size_t.
I can see why this would trigger that warning: CPP / C++ / C Code:
However, I do not see why this should trigger a warning: CPP / C++ / C Code:
Since my code is the second case, I'm still puzzled. __________________
www.blake-foster.com |
|
#8
|
||||
|
||||
Re: Warning C4267: '=' : conversion from 'size_t' to 'unsigned int', possible loss of...It seems to be related to OpenCV. Here's a really simple program that triggers the same warning:
CPP / C++ / C Code:
This causes the following warning: .\main.cpp(8) : warning C4267: 'initializing' : conversion from 'size_t' to 'unsigned int', possible loss of data If I don't include cv.h, I get a clean compile. The only explanation I can think of is that there's a preprocessor definition in one of the OpenCV headers that results in that warning when I dereference the iterator. I can't imagine what that would be, though. I would appreciate any suggestions. __________________
www.blake-foster.com |
|
#9
|
|||
|
|||
Re: Warning C4267: '=' : conversion from 'size_t' to 'unsigned int', possible loss of...Which version of openCV are you using. I'm using 2.x and Intel IPP
It's indirectly caused by openCV, as what TurboPT said, its a 64-bit portability issue. cv.h - > cxcore.h -> cxtypes.h -> stdlib.h -> crtdefs.h crtdefs.h has a macro "_SIZE_T_DEFINED" CPP / C++ / C Code:
I'm using VS2005 Pro. Probably you need to do something at the compiler settings. Disabling to warning won't be complete solution, |
|
#10
|
||||
|
||||
Re: Warning C4267: '=' : conversion from 'size_t' to 'unsigned int', possible loss of...Thanks! However, there's more to it than that. This does not trigger a warning:
CPP / C++ / C Code:
But this does: CPP / C++ / C Code:
Nonetheless, something in one of the OpenCV files is probably affecting the definition of size_t. I'm not sure if it's worth the trouble of searching through all the OpenCV files to find out, though, because that still does not answer the bigger question. The line unsigned int x = *foo.begin(); should not trigger that warning, since *foo.begin(); is an unsigned int, irrespective of the definition of size_t. EDIT: I forgot to mention, I'm using OpenCV 2.1. __________________
www.blake-foster.com |
Recent GIDBlog
R for statistics by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Records and files | kingnuddy | C Programming Language | 19 | 08-Apr-2010 22:14 |
| Problem executing nam-1.13 | RodolfoAlvizu | Computer Software Forum - Linux | 20 | 28-Feb-2009 15:23 |
| I need help in order to fix my bugs in the program I wrote | eli56060 | C Programming Language | 14 | 27-Jan-2008 09:03 |
| Database Program | goldfish | C Programming Language | 6 | 13-May-2006 13:12 |
| [Include] Doubly-linked List | dsmith | C Programming Language | 6 | 14-Apr-2006 13:12 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The