[LCP]Porting code from K&R -> ANSI

Robert Elsner roberte at matchmaker.com
Thu Aug 16 08:03:57 UTC 2001


I found that the biggest issue is this

struct abc {
    char *cs;
    char *cp;
    int aint;
    long along;
};

The pointers in a structure and constant pointers, meaning I cannot rewrite
this data, for instance, pass through a toupcase function.

So what would be a good fix for this?

One way would be to allocate new memory in the function, and return a pointer
to this memory, this works.

But calling malloc is costly. Our code is fast based upon the fact, you can
just rewrite the data.  If this is the only approach, it seems as if we really
can't convert totally to ANSI coding standards.

BTW: -Wwrite-strings is a compiler flag that will warn you about the const
issues




More information about the linuxCprogramming mailing list