What is the working difference between a signed char pointer and an unsigned one?

I can understand the difference between signed char and unsigned . But aren't pointers of the appropriate type equivalent in their work? Cos sizeof(char) and sizeof(unsigned char) always the same (or are there any examples of counters?)

For pointers, only the size of the data type should matter. Are there any pitfalls if I use char * and unsigned char * interchangeably?

I do not find these posts useful :(

Difference between unsigned pointers char and char

Why short * instead of char * for string? Difference between char * and unsigned char *?

+4
source share
2 answers

Here is an example counter based on the difference in type ranges denoted by each type of pointer:

 #include <stdio.h> int main() { unsigned char *uc; char *c; unsigned char v = 128; uc = &v; c = &v; if (*uc != *c) printf("there is difference\n"); return 0; } 
+4
source

The type of pointers tells the compiler about the type of thing the pointer points to, which allows the compiler to make sure that you use the pointer correctly and try to make sure that you are not making any mistakes.

The compiler, with its errors and warnings, is struggling to make sure that the code you are developing is correct. Listen to them - people who write compilers are trying to help you.

+3
source

Source: https://habr.com/ru/post/1402927/


All Articles