Re: A question on variable defination





Eric Sosman wrote On 03/31/06 14:08,:

[... a bunch of nonsense he regrets ...]

sunnylele wrote On 03/31/06 13:11,:

Hi, all,

a question on the following defination:
an external function is defined as:
nmriopen(char *const filename, const int np1, const float step1,
const int np2, const float step2)

what's the difference if it is defined as:
nmriopen(char filename, int np1, float step1,
int np2, float step2)


I assume you mean `char *filename' rather than
`char filename'.

[...]
For the pointer argument things are a little different,
because the thing that is `const' isn't the pointer value
itself, but the thing it points at. (In this case; it's
possible to get the other effect instead, or in addition.)

Ahh, blagnabbit! I mis-read your declaration, and made
a fool of myself. `char * const filename' is a pointer to
`char', where the pointed-to `char' is modifiable but the
pointer variable itself is not. As with the other `const'-
qualified arguments, this is not terribly useful. (Hence
seldom used, hence unfamiliar, hence easily mis-read by
overconfident shoot-from-the-hip people ...)

and what if use "int *const np1" instead of "const int np1"?

A similar effect: The function promises (weakly) not to
use the pointer `np1' to change the value that it points at.

Same mistake by yours truly: The pointer variable `np1'
is unchangeable, but the integer that it points to can be
modified.

--
Eric.Sosman@xxxxxxx

.



Relevant Pages

  • Re: Is this legal ?
    ... >> to be followed again if the compiler can't guarantee that nothing that ... >address of an object into a pointer to const type version, ... to change it (by casting away const from a pointer to it, ...
    (comp.lang.c)
  • Re: Why is the kfree() argument const?
    ... is there any reason why kfreetakes a const pointer just to degrade it ... In the particular case of kfree(), the pointer argument *should* be const, ... If a struct has a constant pointer to it, ...
    (Linux-Kernel)
  • RE: Hyperlink Multiple Files
    ... filename itself, not a path or anything, just filename like MyFile.xls or ... You'll need to change a couple of the Const values in the code to match the ... open your workbook and right-click on the Excel icon just ... Dim partialPath As String ...
    (microsoft.public.excel.misc)
  • Re: modifying const qualified object indirectly
    ... through a const struct pointer. ... const-ness) are correct generally depend on the qualification of the definition ... void flip ...
    (comp.lang.c)
  • Re: How to convert Infix notation to postfix notation
    ... correctness and maintainability are what's needed, ... I did point out that const really doesn't accomplish much. ... references to the pointer declared const, ...
    (comp.lang.c)