Whoa, whoa, what's all this hysteria? On 13 September 2010 16:33, Mike Caron <[email protected]> wrote: > On 9/12/2010 10:31 PM, Seth Hetu wrote: >>> >>> I have a feeling that this should be illegal in FB. I could totally see >>> FB forgetting that it stored a variable in its nondeclared variable >>> storage and overwriting it in a later function.
Temporary values are allocated on the stack in the same way as local variables. Anyway FB is forced to allow passing constants byref, because QBASIC has always allowed it. And we use it all over the place in the OHR; it's quite useful. This is quite a nuisance for fb2c++ though. >> I'd definitely avoid this situation with gusto. Consider passing '3' >> (just the number) as "by ref" into the parameter 'x' ---what happens >> if the compiler inlines that variable, copying it to each place the >> variable is used inside the function? That becomes problematic for, >> e.g.,: >> x = 10 >> ....which becomes: >> 3 = 10 That's not how function inlining works. And fbc is miles off doing any optimisations as significant as function inlining anyway. >> That, at least, is the reason it's illegal in C++ ---not sure what >> the FB compiler says if you try this. I don't think so. C++ can pass other types of temporary values by reference, so I assume the reason it's illegal is that if you're passing "3" by reference, it's probably an unintentional bug. Passing by reference indicates that you want to pass a *variable* instead of a value. And like I said, it works in FB. >> (Of course, in early Fortran >> dialects, side-effecting 3 to 10 was completely possible... but that's >> a whole different can of worms (and I've been told it doesn't work in >> newer compilers).) > > I imagine that any sane compiler would turn that situation into this: > > dim temp as integer = 3 > > byrefsub(temp) Of course. That's exactly what it does. _______________________________________________ Ohrrpgce mailing list [email protected] http://lists.motherhamster.org/listinfo.cgi/ohrrpgce-motherhamster.org
