Вопрос

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