gcc error cast from loses precision Veyo Utah

Address Saint George, UT 84771
Phone (435) 652-4470
Website Link http://sssonline.com

gcc error cast from loses precision Veyo, Utah

Comment 5 Jonathan Wakely 2012-07-19 16:12:18 UTC Does changing the definition of POINTER_HASH to use intptr_t instead of long work? share|improve this answer edited Jul 24 '12 at 8:07 Destroyica 1,7001730 answered Jan 8 '10 at 1:38 Reed Copsey 396k377951117 (unsigned int) self -> (intptr_t) self worked for me I've tried static_cast(obj), reinterpret_cast(obj), and various combinations of C style casts, intptr_t's, unsigned int's, and I'm including stdint.h. A rather common thing to do.

In what atmospheric densities or pressures have aerobrakings been performed? Read more 12.10.2016 Toyota: 81 514 issues in the code A story about the fact that the software is penetrating more and more in our daily life. While the pointer points to an address in the first 4 GB, the upper 32 bits will be 0 and you won't lose any data. Kai, perhaps you may help out?

I ended up casting the pointer to long and the code worked.. c++ casting void-pointers share|improve this question edited Oct 28 '09 at 22:28 sbi 135k35179350 asked Oct 28 '09 at 22:04 Joshua D. If the reason for the cast is to make the pointer opaque, then void* already achieves this, so the code could use void* instead of int. Comment 15 Jakub Jelinek 2012-07-20 15:54:08 UTC That patch can't work properly, on targets where uintptr_t isn't unsigned long you'll either get warnings from using %lx for it, or it will

Using built-in specs. Is there a role with more responsibility? You first convert to an integer type large enough to hold the pointer, and then you narrow it anyway. more hot questions question feed lang-cpp about us tour help blog chat data legal privacy policy work here advertising info mobile contact us feedback Technology Life / Arts Culture / Recreation

dynamic_cast1823Cast int to enum in C#1384Do I cast the result of malloc?39error: cast from 'void*' to 'int' loses precision1Casting error with GetModuleFileNameW1error: cast from 'char*' to 'unsigned int' loses precision-3error: cast Join them; it only takes a minute: Sign up error: cast from 'Foo*' to 'unsigned int' loses precision up vote 0 down vote favorite 1 I'm trying to cast a pointer Boyd 2,60421630 10 Not valid on Windows 64 - long is still 32-bit but pointers are 64-bit. –Jonathan Leffler Oct 28 '09 at 22:13 That's not a good Physically locating the server Book of zen kōans Appease Your Google Overlords: Draw the "G" Logo Why does argv include the program name?

more stack exchange communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour Start here for a quick overview of the site Help Center Detailed The int doesn't have enough space to store all the data in the pointer, and because of that you lose information if you convert the pointer to int. This will get you a pointer from a 32 bit offset: int32 nOffset = 762; // random offset char * pOffset = NULL; // pointer to hold offset pOffset += nOffset; Comment 3 Jonathan Wakely 2012-09-15 17:57:52 UTC Or strictly, should be rejected by any 64-bit compiler with 32-bit int (which is practically all of them) and any 32-bit compiler with 16-bit

That could create all kinds of trouble. –sbi Oct 28 '09 at 22:38 1 pthread passes the argument as a void*. Export The $PATH Variable, Line-By-Line Why does this execution plan have Compute Scalars? I'm not going to weigh in on whether it's right or wrong to abuse a void* this way. I strongly disagree.

cov(x,y)=0 but corr(x,y)=1 more hot questions question feed lang-cpp about us tour help blog chat data legal privacy policy work here advertising info mobile contact us feedback Technology Life / Arts Are there any rules or guidelines about designing a flag? 5008 out of the box How should I interpret "English is poor" review when I used a language check service before The OP tried this directly, and your answer still does it, except that it converts to 64-bit integer first, and then to 32-bit integer. Exploded Suffixes Where are sudo's insults stored?

On implementations where long long is just as large as a pointer, it's not any better than the already-posted answers of either (u)intptr_t or %p. (And on the rare implementations where This will trigger undefined behavior as soon as convert back to pointer and make use of the address. –jogojapan Mar 12 '13 at 4:06 @jogjopan: What is said by From what I've read, one of the many things I've tried should work. intptr_t test = reinterpret_cast(obj) does not work. –Alex Oct 9 '10 at 22:42 Is it the same error when using intptr_t? –Ben Voigt Oct 9 '10 at 22:42

But you seem to suggest by your answer that the user can pass 5 to pthread_create and then perform the above cast to get it back. –Loki Astari Oct 29 '09 You either need to cast the argument cast to uintptr_t afterwards to (unsigned long), or some other type and adjust %lx to something matching it. share|improve this answer answered Jan 8 '10 at 1:35 silentbicycle 96748 Oh well.. Description Rainer Emrich 2012-07-10 07:59:47 UTC bootstrap native x86_64-w64-mingw32 fails at stage 2: /SCRATCH/tmp.pBPKMqodMC/gcc-4.7.2/gcc-4.7.2/./prev-gcc/g++ -B/SCRATCH/tmp.pBPKMqodMC/gcc-4.7.2/gcc-4.7.2/./prev-gcc/ -B/opt/devel/gnu/gcc/MINGW_NT/x86_64-w64-mingw32/mingw-w64-runtime-trunk-svn/gcc-4.7.2/x86_64-w64-mingw32/bin/ -nostdinc++ -B/SCRATCH/tmp.pBPKMqodMC/gcc-4.7.2/gcc-4.7.2/prev-x86_64-w64-mingw32/libstdc++-v3/src/.libs -B/SCRATCH/tmp.pBPKMqodMC/gcc-4.7.2/gcc-4.7.2/prev-x86_64-w64-mingw32/libstdc++-v3/libsupc++/.libs -I/SCRATCH/tmp.pBPKMqodMC/gcc-4.7.2/gcc-4.7.2/prev-x86_64-w64-mingw32/libstdc++-v3/include/x86_64-w64-mingw32 -I/SCRATCH/tmp.pBPKMqodMC/gcc-4.7.2/gcc-4.7.2/prev-x86_64-w64-mingw32/libstdc++-v3/include -I/SCRATCH/tmp.pBPKMqodMC/src/gcc-4.7.2/libstdc++-v3/libsupc++ -L/SCRATCH/tmp.pBPKMqodMC/gcc-4.7.2/gcc-4.7.2/prev-x86_64-w64-mingw32/libstdc++-v3/src/.libs -L/SCRATCH/tmp.pBPKMqodMC/gcc-4.7.2/gcc-4.7.2/prev-x86_64-w64-mingw32/libstdc++-v3/libsupc++/.libs -c -g -O2 -D__USE_MINGW_ACCESS -Wno-pedantic-ms-format -gtoggle -DIN_GCC

c++ casting share|improve this question asked Aug 26 '14 at 3:17 Khue 278115 1 Why are you casting a pointer to unsigned long? –0x499602D2 Aug 26 '14 at 3:20 3 If you suppresses the errors, this could even work for a while. Then just using the low order bits is not appropriate either, I think. The correct answer is, if one does not mind losing data precision, int x = *((int*)(&arg)); This works on GCC4.

cf. Why would a password requirement prohibit a number in the last character? Make all the statements true In a long sum, how can we find how many terms are preceded by the plus (or minus) sign Book of zen kōans In what atmospheric In C89 mode it also works: #include void myfunc(struct Foo* obj) { uintptr_t temp = (uintptr_t)obj; } Comeau C/C++ (Oct 6 2008 11:28:09) for ONLINE_EVALUATION_BETA2 Copyright 1988-2008 Comeau Computing.

Something else about the call, typically another argument, tells the function if the pointer argument is actually a pointer to some data, or just an integer that has been 'upcast' to For C++ basically the same should apply, just the cast would be reinterpret_cast(x). Chebyshev Rotation Why was the identity of the Half-Blood Prince important to the story? how can you tell if the engine is not brand new?

It's an int type guaranteed to be big enough to contain a pointer. Or use long (is typically 64-bit on 64-bit platforms on the GCC compiler) or long long (a C99 types which most, but not all compilers, support in C++), or some other date: invalid date '2016-10-16' Why does this execution plan have Compute Scalars? The next failure now is: /SCRATCH/tmp.xipisatGtI/gcc-4.8.0/gcc-4.8.0/./prev-gcc/g++ -B/SCRATCH/tmp.xipisatGtI/gcc-4.8.0/gcc-4.8.0/./prev-gcc/ -B/opt/devel/gnu/gcc/MINGW_NT/x86_64-w64-mingw32/mingw-w64-runtime-trunk-svn/gcc-4.8.0/x86_64-w64-mingw32/bin/ -nostdinc++ -B/SCRATCH/tmp.xipisatGtI/gcc-4.8.0/gcc-4.8.0/prev-x86_64-w64-mingw32/libstdc++-v3/src/.libs -B/SCRATCH/tmp.xipisatGtI/gcc-4.8.0/gcc-4.8.0/prev-x86_64-w64-mingw32/libstdc++-v3/libsupc++/.libs -I/SCRATCH/tmp.xipisatGtI/gcc-4.8.0/gcc-4.8.0/prev-x86_64-w64-mingw32/libstdc++-v3/include/x86_64-w64-mingw32 -I/SCRATCH/tmp.xipisatGtI/gcc-4.8.0/gcc-4.8.0/prev-x86_64-w64-mingw32/libstdc++-v3/include -I/SCRATCH/tmp.xipisatGtI/src/gcc-4.8.0/libstdc++-v3/libsupc++ -L/SCRATCH/tmp.xipisatGtI/gcc-4.8.0/gcc-4.8.0/prev-x86_64-w64-mingw32/libstdc++-v3/src/.libs -L/SCRATCH/tmp.xipisatGtI/gcc-4.8.0/gcc-4.8.0/prev-x86_64-w64-mingw32/libstdc++-v3/libsupc++/.libs -c -g -O2 -D__USE_MINGW_ACCESS -Wno-pedantic-ms-format -gtoggle -DIN_GCC -fno-exceptions -fno-rtti -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute

Modified: trunk/gcc/ChangeLog trunk/gcc/stmt.c Comment 35 Kai Tietz 2012-12-10 10:01:24 UTC Fixed on trunk and 4.7 branch Comment 36 Kai Tietz 2012-12-20 19:23:29 UTC *** Bug 55165 has been marked as a How should I calculate the determinant? more stack exchange communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour Start here for a quick overview of the site Help Center Detailed I'll check the C specification. –ecatmur Feb 5 '14 at 10:41 Casting a wide signed integer type to a narrow one is not defined behavior, one should definitively use

Thank you in advance for any suggestions! So you know you can cast it back like this int myData = reinterpret_cast(arg); even though the compiler doesn't know you only ever pass myFcn to pthread_create in conjunction with an Please tell me ... –Ben Oct 28 '09 at 22:47 | show 2 more comments Your Answer draft saved draft discarded Sign up or log in Sign up using Google Waving this warning away could have fatal behavior as your addresses get chopped in half.

Why do train companies require two hours to deliver your ticket to the machine? Modified: trunk/gcc/ChangeLog trunk/gcc/ggc-common.c Comment 32 Kai Tietz 2012-12-10 09:53:13 UTC Author: ktietz Date: Mon Dec 10 09:53:08 2012 New Revision: 194348 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=194348 Log: PR target/53912 * print-tree.c (print_node): Cast from Consider the case if user has to make a generic array (in C where there is no template). Comment 20 Jakub Jelinek 2012-09-20 10:14:35 UTC GCC 4.7.2 has been released.

Fundamentally, treating the bits of a pointer as if they were an integer is not a portable thing to do (although it can be made to work on many platforms). If the reason for the cast is to achieve compatibility with some existing library (perhaps an older callback interface) which cannot be modified, then I think you need to review the This is likely to be the case with TThread::Printf as well. Code like this used to work and it's kind of obvious what it is supposed to mean.