Should function argument be changed in function body?

C

Chris Torek

It has a much more obnoxious effect. If I <= LAST on entry it gives
an infinite loop and quite some UB. ;-).

Oops. Swap the first two quoted lines, yes. :) Also, the third line
should say "CALL COMPUT...", though of course this was really shorthand
for "some computation using X(I)".

(It has been at least 20 years since I wrote any Fortran, and even
then I used various RATFOR variants -- the one on BSD Unix, and
before that, the one I wrote for myself to use with Microsoft's
F80 on my TRS-80. Of course I had to write that one in Fortran.)
 
E

Ed Prochak

Chris said:
It is in some other, non-C languages:

SUBROUTINE FOO(X, I, LAST)
INTEGER I, LAST
REAL X(LAST)
IF (I .GT. LAST) GOTO 20
10 CONTINUE
COMPUT(X(I))
I = I + 1
GOTO 10
20 CONTINUE
RETURN
END

Here, this Fortran code has the obnoxious side effect of incrementing
the variable you call it with:

...
CALL FOO(ARR, I, 20)
C now I .EQ. 21

Perhaps some of the dogmatic "never modify a parameter" is left over
from old Fortran coders. :)

Chris, you've been writing C for() loops for too long. That function
NEVER returns! 8^)

Ed
(You need the 10 on the IF line.)
 
M

Michael Wojcik

You've peaked my curiosity,

Impressive. Most people's curiosity generally gets piqued; peaking it
requires something *really* curious.
on what implementations
(excluding the infamous DeathStation 9000) is a
size_t not defined as an 'unsigned int' ?

Well, most I32LP64 implementations, I imagine.
 
C

CBFalconer

Michael said:
Impressive. Most people's curiosity generally gets piqued;
peaking it requires something *really* curious.

I can see direct applicability to a PHB. :)
 
P

pete

Chris said:
Do you often have strings over 2GB long?

That has nothing to do with anything.
The only systems I know of
where it's likely to be too small in practical uses are a few 16 bit
ones.


Someone has to implement strlen...

Portable C is poor choice to implement a standard library function,
in a real implementation of the standard library.
length_of_string is supposed to be portable C, isn't it?
 
M

Mark

Michael Wojcik said:
Impressive.

Thank you.
Most people's curiosity generally gets piqued;

peaked curiosity (googled) 85,300 hits
piqued curiosity (googled) 139,000 hits
I'll give you 'more' people... but not most ;)
peaking it requires something *really* curious.

Are you sure about that?
peaked : To bring to a maximum of development, value, or intensity
pique : French, a prick, irritation, from Old French, from piquer, to prick,
from Vulgar Latin *piccre, ultimately of imitative origin.]

What??? Come on, a french prick irritation???
I guess what you call pique we call the clap! :)

Regards,
Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top