B
Ben Petering
Hi group,
this is a 'best practice' type question (I want discussion of the issue
- whys and why nots - similar to "casting the return value of malloc()",
to cite an analogous case).
Let's say I have a function written in assembler/(some non-C language)
which takes one pointer-to-const-char arg, the declaration being:
extern unsigned int str_len(const char *s);
Is the 'const' type qualifier 1) advisable and 2) legal? The C compiler
has no way of enforcing what a non-C function does with the pointer, and
as I understand it, the type qualifier is a guarantee of sorts - the
compiler guarantees said l-value will not be modified using the passed
pointer.
If I'm not mistaken, this makes the presence of the qualifier
inadvisable. Correct?
Response appreciated. Apologies for possible OT or incorrect terminology.
-ben
this is a 'best practice' type question (I want discussion of the issue
- whys and why nots - similar to "casting the return value of malloc()",
to cite an analogous case).
Let's say I have a function written in assembler/(some non-C language)
which takes one pointer-to-const-char arg, the declaration being:
extern unsigned int str_len(const char *s);
Is the 'const' type qualifier 1) advisable and 2) legal? The C compiler
has no way of enforcing what a non-C function does with the pointer, and
as I understand it, the type qualifier is a guarantee of sorts - the
compiler guarantees said l-value will not be modified using the passed
pointer.
If I'm not mistaken, this makes the presence of the qualifier
inadvisable. Correct?
Response appreciated. Apologies for possible OT or incorrect terminology.
-ben