The reason for the warning is that the compiler suspects you might be trying to round-trip a pointer through int
and back. This was common practice before the advent of 64-bit machines and it is not safe or reasonable. Of course here the compiler can clearly see that you’re not doing this, and it would be nice if it were smart enough to avoid the warning in cases like this, but it’s not.
A clean alternative that avoids the warning, and another much nastier issue of wrong result when the converted value is negative, is:
unsigned int offset = (uintptr_t) dst % blkLen;
You’ll need to include stdint.h
or inttypes.h
to have uintptr_t
available.
Related Posts:
- Warning: assignment from incompatible pointer type
- difference between
and - Warning/error “function declaration isn’t a prototype”
- Returning an array using C
- warning: initializer element is not computable at load time
- Undefined reference to main – collect2: ld returned 1 exit status
- Excess elements of scalar initializer for pointer to array of ints
- Where is the
header file on Linux? Why can’t I find ? - What exactly is meant by “de-referencing a NULL pointer”?
- Realloc Invalid Pointer in C
- typedef fixed length array
- How to solve static declaration follows non-static declaration in GCC C code?
- Pointer to 2D arrays in C
- Pointer to a string in C?
- Using pointer to char array, values in that array can be accessed?
- Pointer Arithmetic
- C pointers and arrays: [Warning] assignment makes pointer from integer without a cast
- warning: incompatible implicit declaration of built-in function ‘xyz’
- Passing by reference in C
- Why does the arrow (->) operator in C exist?
- Difference between char* and const char*?
- #31 expression must have integral type
- How do you pass a function as a parameter in C?
- How to make an array with a dynamic size? General usage of dynamic arrays (maybe pointers too)?
- Constant pointer vs Pointer to constant
- How to initialize array to 0 in C?
- Is the sizeof(some pointer) always equal to four?
- Sign extend a nine-bit number in C
- make: Nothing to be done for `all’
- How to printf a memory address in C
- What is the use of intptr_t?
- Data argument not used by format strings in C
- execv vs execvp, why just one of them require the exact file’s path?
- expected expression before ‘{‘ token
- Setting std=c99 flag in GCC
- C Vector/ArrayList/LinkedList
- error: ‘for’ loop initial declarations are only allowed in C99 mode [duplicate]
- c – warning: implicit declaration of function ‘printf’
- Flushing buffers in C
- Undefined Reference issues using Semaphores
- What is time(NULL) in C?
- char pointers: invalid conversion from ‘char*’ to ‘char’?
- Compiling a .C file: Undefined symbols for architecture x86_64
- Portable way to check if directory exists [Windows/Linux, C]
- How to use EOF to run through a text file in C?
- Incorrect checksum for freed object on malloc
- Removing trailing newline character from fgets() input
- Simple way to check if a string contains another string in C?
- What does “request for member ‘*******’ in something not a structure or union” mean?
- gcc: undefined reference to
- Segmentation fault (core dumped) due to fgets – I think
- C subscripted value is neither array nor pointer nor vector when assigning an array element value
- What does “request for member ‘*******’ in something not a structure or union” mean?
- Unknown ending signal when using debugger gdb
- Valgrind: invalid read of size 4 -> sigsegv, works fine without valgrind and in visual studio
- Is there a good Valgrind substitute for Windows?
- Difference between sizeof(char) and sizeof(char *)
- Difference between “move” and “li” in MIPS assembly language
- How to empty a char array?
- How can one see content of stack with GDB?
- What does the term “empty loop” refer to exactly in C and C++?
- Invalid type argument of -> C structs
- What does ** mean in C?
- Is there a way to have printf() properly print out an array (of floats, say)?
- What integer hash function are good that accepts an integer hash key?
- Proper way to empty a C-String
- malloc(): memory corruption
- How do you allow spaces to be entered using scanf?
- X86 assembly – Handling the IDIV instruction
- Pause screen at program completion in C
- Get size of pointer in C
- Difference between fgets and fscanf?
- How do I compile the asm generated by GCC?
- What is the difference between %g and %f in C?
- Structure padding and packing
- Lua – Number to string behaviour
- Reading in double values with scanf in c
- Difference between char* and char** (in C)
- The difference between char * and char[] [duplicate]
- What tools are there for functional programming in C?
- “-bash: gcc: command not found” using cygwin when compiling c?
- In C, what exactly happens when you pass a NULL pointer to strcmp()?
- What are the differences between if, else, and else if?
- Difference between the int * i and int** i
- strtok segmentation fault
- Invalid write of size 1
- Linker error: “linker input file unused because linking not done”, undefined reference to a function in that file
- realloc(): invalid next size when reallocating to make space for strcat on char *
- Constructor for structs in C
- C Error: declaration shadows a local variable — Won’t let me repeatedly replace the value of my float variable
- MIPS to C Translation
- gdb: No symbol “i” in current context
- Cross Platform C library for GUI Apps?
- Implicit function declarations in C
- Pre increment vs Post increment in array
- Convert long long to string in C?
- how to stop a loop arduino
- How to normalize a mantissa
- Initialization makes pointer from integer without a cast – C
- lvalue required as increment operand