On 2023-02-17 08:44, David Malcolm wrote:
This is possibly a silly question, but what *are* these safe
alternatives? [1] How does one test to see if an object has been
reallocated?

Oops sorry, I snipped off that part when pasting from the man page. Typically such conditionals are used to update pointers within structs (and in some overly adventurous cases, continue using the old pointer!) and the alternative is to save offsets in structs and not pointers.

The text I missed quoting here:

"""
        void adjust_pointers (int**, int);

        void grow (int **p, int n)
        {
          int **q = (int**)realloc (p, n *= 2);
          if (q == p)
            return;
          adjust_pointers ((int**)q, n);
        }

To avoid the warning at this level, store offsets into allocated memory instead of pointers. This approach obviates needing to adjust the stored pointers after reallocation.
"""

Sid

Dave
[1] Would suggesting "rust" here be too snarky? :-P

I think the equivalent American expression is "lets take this outside" ;)

Reply via email to