[freetds] tdsstring.c ansi alias problem

Craig A. Berry craigberry at mac.com
Sun May 4 23:26:27 EDT 2003

My compiler (Compaq C V6.5-001 on OpenVMS Alpha V7.3-1) doesn't like the following snippet of src/tds/tdsstring.c:

        *(char **) s = src;
%CC-W-BADANSIALIAS, This statement uses the type "pointer to char" to reference the same storage location as the statement at line number 113 in file D0:[CRAIG.FREETDS-0_62_DEV_20030503.SRC.TDS]TDSSTRING.C;1, which uses the type "pointer to struct DSTR_CHAR".  This does not conform to the ANSI aliasing rules.
at line number 112 in file D0:[CRAIG.FREETDS-0_62_DEV_20030503.SRC.TDS]TDSSTRING.C;1

The complete function where this occurs is:

tds_dstr_set(DSTR * s, char *src)
        if (*(char **) s != tds_str_empty)
                free(*(char **) s);
        *(char **) s = src;
        return *s;

I guess I don't understand the purpose of casting the left-hand side of "*(char **) s = src;" rather than the right, or why it's cast as a double pointer and then dereferenced rather than just being cast as a single pointer.   My confusion wouldn't really be relevant except that it prevents me from knowing what to do about this.  I can suppress ANSI aliasing by adding the appropriate compiler flag, but I don't know how hot this bit of code is or whether the optimizations allowed by aliasing would make any real difference.
Craig A. Berry
mailto:craigberry at mac.com

"... getting out of a sonnet is much more
 difficult than getting in."
                 Brad Leithauser

More information about the FreeTDS mailing list