So reinterpret_cast has casted it to long type and then static_cast safely casts long to int, if you are ready do truncte the data. The pointer doesn't actually point to anything, but it's the result of an earlier cast from an integer to a pointer (e.g. Staging Ground Beta 1 Recap, and Reviewers needed for Beta 2. My code is GPL licensed, can I issue a license to have my code be distributed in a specific MIT licensed project? C99 standard library provides intptr_t and uintptr_t typedefs, which are supposed to be used whenever the need to perform such a cast comes about. To subscribe to this RSS feed, copy and paste this URL into your RSS reader. ../lib/odp-util.c:5665:7: note: expanded from macro 'SCAN_SINGLE' If the destination type is bool, this is a boolean conversion (see below). And then assign it to the double variable. Site design / logo 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. What can a lawyer do if the client wants him to be acquitted of everything despite serious evidence? Sign up for a free GitHub account to open an issue and contact its maintainers and the community. whether it was an actual problem is a different matter though. By clicking Accept all cookies, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. The problem is not with casting, but with the target type loosing half of the pointer. For the Nozomi from Shinagawa to Osaka, say on a Saturday afternoon, would tickets/seats typically be available - or would you need to book? Use #include to define it. This will get you a pointer from a 32 bit offset: A function pointer is incompatible to void* (and any other non function pointer). 10) A prvalue of type pointer to void (possibly cv-qualified) can be converted to pointer to any object type. ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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. If you cast an int pointer int, you might get back a different integer. By clicking Accept all cookies, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. Please unaccept the answer you have chosen as it is wrong (as the comments below it say) and will lead to bugs. Is it possible to create a concave light? The difference between the phonemes /p/ and /b/ in Japanese, Styling contours by colour and by line thickness in QGIS. Browse other questions tagged, Where developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide. By clicking Post Your Answer, you agree to our terms of service, privacy policy and cookie policy. Euler: A baby on his lap, a cat on his back thats how he wrote his immortal works (origin? Thus as a result it may be less error prone to generate a pointer dynamcially and use that. this way you won't get any warning. My code is GPL licensed, can I issue a license to have my code be distributed in a specific MIT licensed project? If any, how can the original function works without errors if we just ignore the warning. Again, all of the answers above missed the point badly. use $(ARCHS_STANDARD_32_BIT) at Architecture instead of $(ARCHS_STANDARD). Using Kolmogorov complexity to measure difficulty of problems? You can fix this error by replacing this line of code. What is the point of Thrower's Bandolier? If it's anything like cocos2d-iphone v2.x and just based on this slice of code in a core class I wager it's safe to say that cocos2d-x 2.x also is not compatible with 64 bit code, and you can expect all kinds of issues (not just compile-time but also runtime). In Java, there are two types of casting: Widening Casting (automatically) - converting a smaller type to a larger type size. } SCAN_END_SINGLE(ATTR) : iPhone Retina 4-inch 64-bit) is selected. Making statements based on opinion; back them up with references or personal experience. If pointers are 64 bits and ints are 32 bits, an int is too small to hold a pointer value. I'm unfamiliar with XCode, but the solution should be something like follows: Most of the "solutions" above can lose part of the pointer address when casting to a smaller type. How Intuit democratizes AI development across teams through reusability. How to use Slater Type Orbitals as a basis functions in matrix method correctly? Please help me compile Chez Scheme. The nature of simulating nature: A Q&A with IBM Quantum researcher Dr. Jamie We've added a "Necessary cookies only" option to the cookie consent popup. ERROR: incompatible integer to pointer conversion assigning to 'string' (aka 'char *') from 'int', error: cast to 'string' (aka 'char *') from smaller integer type 'int' [-Werror,-Wint-to-pointer-cast], error: incompatible integer to pointer conversion assigning to 'string' (aka 'char *') from 'int' C, warning: initialization of 'unsigned char' from 'uint8_t *' {aka 'unsigned char *'} makes integer from pointer without a cast [-Wint-conversion], Minimising the environmental effects of my dyson brain. ^~~~~~~~~~~~~~~~~~~~ The nature of simulating nature: A Q&A with IBM Quantum researcher Dr. Jamie We've added a "Necessary cookies only" option to the cookie consent popup. @DavidHeffernan, sane thread APIs wouldn't send integral data to the thread procedures, they would send pointers. I think the solution 3> should be the correct one. But gcc always give me a warning, that i cannot cast an int to a void*. What you do here is undefined behavior, and undefined behavior of very practical sort. Is it plausible for constructed languages to be used to affect thought and control or mold people towards desired outcomes? Therefore it is perfectly valid for the compiler to throw an error for a line like. ../lib/odp-util.c:5489:33: note: expanded from macro 'SCAN_PUT_ATTR' this way you won't get any warning. Linear regulator thermal information missing in datasheet. This is not even remotely "the correct answer". How do I count the number of sentences in C using ". ../lib/odp-util.c:5834:5: error: cast to smaller integer type 'unsigned long' from 'void *' [-Werror,-Wvoid-pointer-to-int-cast] Taking the above declarations of A, D, ch of the . He should pass the address of the integer, the thread should get that address, Note: This is only appropriate is you cast the. Browse other questions tagged, Where developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide, You should be doing int x = *((int *)arg); You are casting from void * to int that is why you get the warning. @kshegunov said in Number Type Cast: const void * x; int y = int (x); compiles just fine. How do I set, clear, and toggle a single bit? From what I read about casting in the C11 standard, my feeling is, that it is arguable to emit a warning on an explicit conversion. Only the following conversions can be done with static_cast, except when such conversions would cast away constness or volatility. static_cast on the other hand should deny your stripping away the const qualifier. Browse other questions tagged, Where developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide. For the second example you can make sure that sizeof(int) <= sizeof(void *) by using a static_assert -- this way at least you'll get a notice about it. *PATCH] platform/x86: hp-wmi: Fix cast to smaller integer type warning @ 2023-01-23 13:28 Hans de Goede 2023-01-23 13:56 ` Hans de Goede 0 siblings, 1 reply; 2+ messages in thread From: Hans de Goede @ 2023-01-23 13:28 UTC (permalink / raw) To: Mark Gross Cc: Hans de Goede, Andy Shevchenko, platform-driver-x86, kernel test robot Fix the following . We have to pass address of the variable to the function because in function definition argument is pointer variable. The main point is: a pointer has a platform dependent size. You can also convert values from one type to another explicitly using the cast operator (see Chapter 5 ): ( type_name) expression In the following example, the cast operator causes the division of one integer variable by another to be performed as a floating-point operation: int sum = 22, count = 5; double mean = (double)sum / count; The high-order 9 bits of the number are used to hold a flag value, and the result is converted back into a pointer. This returns the first 32 bits of the pointer which may be the top or the bottom depending on big versus little endian, as comment #2 said. Is it suspicious or odd to stand by the gate of a GA airport watching the planes? static const void* M_OFFSET = (void*)64*1024; Since gcc compiles that you are performing arithmetic between void* and an int ( 1024 ). equal to the original pointer: First you are using a define, which is not a variable. Press question mark to learn the rest of the keyboard shortcuts. cast operators [edit] When an expression is used in the context where a value of a different type is expected, conversionmay occur: intn =1L;// expression 1L has type long, int is expectedn =2.1;// expression 2.1 has type double, int is expectedchar*p =malloc(10);// expression malloc(10) has type void*, char* is expected But, sure, in that specific case you can pass a local variable address, type casting integer to void* [duplicate]. If the original type is a void *, converting to an int may lose date on platforms where sizeof(void *) != sizeof(int) (which is true of LP64 programming model). To subscribe to this RSS feed, copy and paste this URL into your RSS reader. vegan) just to try it, does this inconvenience the caterers and staff? Well occasionally send you account related emails. Bulk update symbol size units from mm to map units in rule-based symbology. a is of type int[4], which can be implicitly cast to int* (ie, a pointer to an int) &a is of type int(*)[4] (ie: a pointer to an array of 4 ints). The best way is, if one can, do not do such casting, instead, if the same memory address has to be shared for pointer and int (e.g. Pull requests. (i.e. You think by casting it here that you are avoiding the problem! @Artelius: Which, presumably, is exactly what Joshua did: A C++ reinterpret cast will not solve the problem. Site design / logo 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. and how to print the thread id of 2d array argument? As was pointed out by Martin, this presumes that sizeof(void*)>=sizeof(int). How do I align things in the following tabular environment? To perform a cast, specify the type that you are casting to in parentheses in front of the value or variable to be converted. Do roots of these polynomials approach the negative of the Euler-Mascheroni constant? Not the answer you're looking for? ^~~~~~~~~~~~~~~~~~~~~ For example, if you want to store a 'long' value into a simple integer then you can type cast 'long' to 'int'. For the remaining integral types, the result is the value of the enum if it can be represented by the target type and unspecified otherwise. Mutually exclusive execution using std::atomic? The nature of simulating nature: A Q&A with IBM Quantum researcher Dr. Jamie We've added a "Necessary cookies only" option to the cookie consent popup. Difficulties with estimation of epsilon-delta limit proof. What happens if you typecast as unsigned first? Just re-enforcing the old behavior of Xcode 5.0 and earlier versions, that already cut away parts of the address by casting it to int, won't introduce any new bugs and avoids the need to learn and understand lots of implementation-internal cocos code. tialized" "-Wno-format" "-Wno-incompatible-pointer-types" "-Werror" "-dM" "-U_MSC_VER" "-D_TIMESPEC_DEFINED" "-D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_WA As for the stack, I've written a few libraries using pthreds, thus I don't agree that what you describe "is quite often the case". I don't see how anything bad can happen . Connect and share knowledge within a single location that is structured and easy to search. Site design / logo 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. Star 675. Asking for help, clarification, or responding to other answers. Get the address of a callback function to call dynamically in C++, error: call of overloaded function ambiguous, error: cast from to unsigned int loses precision [-fpermissive]. -1, Uggh. On a 64-bit Windows computer, 'long' is a 32-bit type, and all pointers are 64-bit types. However the actual code in question contains an explicit c-style cast to int. SCAN_SINGLE("skb_priority(", uint32_t, u32, OVS_KEY_ATTR_PRIORITY); A cast is a way of explicitly informing the compiler that you intend to make the conversion and that you are aware that data loss might occur, or the cast may fail at run time. Infact I know several systems where that does not hold. Why are Suriname, Belize, and Guinea-Bissau classified as "Small Island Developing States"? privacy statement. A nit: in your version, the cast to void * is unnecessary. To subscribe to this RSS feed, copy and paste this URL into your RSS reader.