문제

For C programmers.

How can I know if a pointer char *, for example, was initialized by using malloc or realloc? I mean in kind of that function:

char* func(char** x){
    /* need some reallocating of *x but 
     * *x can be a pointer to const string
     */
}
도움이 되었습니까?

해결책

There's no portable way to determine whether a pointer refers to a static or auto variable, or to memory allocated via the *alloc functions, by looking at the pointer value alone. If you are intimately familiar with the memory model on your platform you could make some educated guesses, but that's about it.

Otherwise, if it matters, you will have to track that information yourself.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top