modifying struct pointer declared `const'

Julius Plenz plenz at
Wed Apr 6 14:01:00 CEST 2011


At some point in the cgit source code, I see constructs like the
following from ui-repolist.c:32:

    static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime)

Though *repo is declared `const', you want to modify it, so you place
a "writable" version on the stack:

    struct cgit_repo *r = (struct cgit_repo *)repo;

IMO this breaks semantics; why not just declare the parameter `struct
cgit_repo *', so that it's clear the called function may (or indeed
does) modify it?


More information about the CGit mailing list