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?
- Arrow operator (->) usage in C
- Pointer Arithmetic
- What does “dereferencing” a pointer mean?
- What does “dereferencing” a pointer mean?
- char *array and char array[]
- Convert char to int in C and C++
- C pointers and arrays: [Warning] assignment makes pointer from integer without a cast
- What is the difference between const int*, const int * const, and int const *?
- what is stack smashing (C)?
- What is the difference between const int*, const int * const, and int const *?
- 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*?
- Fatal error: iostream: No such file or directory in compiling C program using GCC
- What does ** do in C language?
- #31 expression must have integral type
- How do you pass a function as a parameter in C?
- Invalid pointer error on invoking free() after malloc in C
- conflicting types error when compiling c program using gcc
- expression must have integral type
- How do you pass a function as a parameter in C?
- What is a file with extension .a?
- How to make an array with a dynamic size? General usage of dynamic arrays (maybe pointers too)?
- expression must have integral type
- How do you pass a function as a parameter in C?
- C free(): invalid pointer
- What’s wrong with my code? What is argv[1]?
- gcc/g++: “No such file or directory”
- Valgrind: Invalid read of size 1
- Constant pointer vs Pointer to constant
- Reversing a string in C
- waitpid, wnohang, wuntraced. How do I use these
- Warning: return from incompatible pointer type in C
- How to initialize array to 0 in C?
- Is the sizeof(some pointer) always equal to four?
- How to do scanf for single char in C
- Sign extend a nine-bit number in C
- Break statement not within loop or switch in C
- How to properly malloc for array of struct in C
- Cache Simulator in C
- strcmp giving segmentation fault
- C: error: expected ‘)’ before ‘;’ token
- Where is the C auto keyword used?
- make: Nothing to be done for `all’
- (.text+0x20): undefined reference to `main’ and undefined reference to function
- Why am I getting this error: “data definition has no type or storage class”?
- Initialization from incompatible pointer type warning when assigning to a pointer
- Typedef function pointer?
- 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
- Convert char array to a int number in C
- Bind failed: Address already in use
- Error: initializer element is not computable at load time
- What is the difference between %f and %lf in C?
- Debug vs Release in CMake
- What is stdin in C language?
- Debug vs Release in CMake
- How to prevent multiple definitions in C?
- How to pass 2D array (matrix) in a function in C?
- error: ‘for’ loop initial declarations are only allowed in C99 mode [duplicate]
- How can you print multiple variables inside a string using printf?
- c – warning: implicit declaration of function ‘printf’
- Flushing buffers in C
- What are 0x01 and 0x80 representative of in C bitwise operations?
- How to make parent wait for all child processes to finish?
- warning: passing argument ’from incompatible pointer type [enabled by default]’
- Undefined Reference issues using Semaphores
- What is time(NULL) in C?
- Use of cudamalloc(). Why the double pointer?
- C dynamically growing array
- Why should we check WIFEXITED after wait in order to kill child processes in Linux system call?
- char pointers: invalid conversion from ‘char*’ to ‘char’?
- Compiling a .C file: Undefined symbols for architecture x86_64
- How to compile makefile using MinGW?
- Mapping a numeric range onto another
- Why are hexadecimal numbers prefixed with 0x?
- Portable way to check if directory exists [Windows/Linux, C]
- OpenGL — GL_LINE_LOOP —
- too many arguments for format [-Wformat-extra-args]