C pointer problems in VMS.
Richard Harter
g-rh at cca.CCA.COM
Tue Mar 22 03:46:42 AEST 1988
In article <3072 at haddock.ISC.COM> karl at haddock.ima.isc.com (Karl Heuer) writes:
>In article <25667 at cca.CCA.COM> g-rh at CCA.CCA.COM.UUCP (Richard Harter) writes:
>>>char *wr(a) int a; { body }
>>>main() {
>> <------- char *wr() goes here, your code declares wr as
>> a function returning an int (the default if there
>> is no declaration.)
>
>True, if wr() and main() were in separate files. I assume from the way the
>question was asked that the definition of wr() appeared above main() in the
>same file, in which case the definition itself serves as a declaration.
>(Also, I consider it bad practice to declare a function with local scope, so
>I'd put it outside main() anyway, even if nobody else calls it.)
Consider me confused. What do you mean by declaring a function with
local scope? Are you saying that you are a one-function per file advocate
or that one shouldn't declare static functions?
It does matter (but not in this case) if the function appears after
its use. Put wr after main, and you will get nasty little messages about
redeclaring the type of wr.
>Even if that mistake was made, my knowledge of the VAX architecture suggests
>that it would not have caused the problem, so I suspect that the bug lies in
>the body of wr().
As you say, there is no problem on a VAX, since pointers and ints
are the same size and have the same format, etc. I believe you are correct
in saying that the earlier declaration is honored in code below. I say
'believe' because that this is sort of thing that 'I prefer not to know'.
Declare everything right is my motto; anything else lays the groundwork
for cryptic bugs and exercises in working out what the compiler really did.
Life is too short to solve the problems created by taking shortcuts. :-)
--
In the fields of Hell where the grass grows high
Are the graves of dreams allowed to die.
Richard Harter, SMDS Inc.
More information about the Comp.lang.c
mailing list