Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.85k stars 527 forks source link

function prototypes #158

Closed p5pRT closed 20 years ago

p5pRT commented 24 years ago

Migrated from rt.perl.org#963 (status was 'resolved')

Searchable as RT963$

p5pRT commented 24 years ago

From @vlbrown

If I declare (and or define) my function before I use it

  sub func() {   return 1;   }

  $returned = func(17);

  print $returned;

Then I get a fatal error if the protptype doesn't match.

  Too many arguments for main​::func at foo.pl line 7\, near "17)"   Execution of foo.pl aborted due to compilation errors.

However\, if the function is not declared until after the call

  $returned = func(17);

  print $returned;

  sub func() {   return 1;   }

There is no error (fatal or otherwise).

This violates the Principle of Least Astonishment.

I could buy the argument that this is Difficult To Solve. I think it's a bug even so.

Nevertheless\, it would be useful at least if -w would warn about   Prototype declared too late in code or something similar so that folks like me who put the functions at the end of the script would have some warning (and folks who \ mistakenly use C-style declarations of functions would at least hear from -w).

Perl Info ``` Site configuration information for perl 5.00502: Configured by rdm at Sun Feb 7 16:25:31 PST 1999. Summary of my perl5 (5.0 patchlevel 5 subversion 2) configuration: Platform: osname=freebsd, osvers=2.2.8-release, archname=i386-freebsd uname='freebsd cfcl.com 2.2.8-release freebsd 2.2.8-release #0: fri jan 15 18:39:18 pst 1999 rdm@cfcl.com:usrsrcsyscompilefreebie i386 ' hint=recommended, useposix=true, d_sigaction=define usethreads=undef useperlio=undef d_sfio=undef Compiler: cc='cc', optimize='-O', gccversion=2.7.2.1 cppflags='-I/usr/local/include' ccflags ='-I/usr/local/include' stdchar='char', d_stdstdio=undef, usevfork=true intsize=4, longsize=4, ptrsize=4, doublesize=8 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 alignbytes=4, usemymalloc=n, prototype=define Linker and Libraries: ld='ld', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /usr/lib libs=-ldb -lm -lc -lcrypt libc=/usr/lib/libc.so.3.1, so=so, useshrplib=false, libperl=libperl.a Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' ' cccdlflags='-DPIC -fpic', lddlflags='-Bshareable -L/usr/local/lib' Locally applied patches: @INC for perl 5.00502: /usr/local/lib/perl5/5.00502/i386-freebsd /usr/local/lib/perl5/5.00502 /usr/local/lib/perl5/site_perl/5.005/i386-freebsd /usr/local/lib/perl5/site_perl/5.005 . Environment for perl 5.00502: HOME=/home/vlb LANG (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/home/vlb/bin:/usr/local/bin:/usr/local/nib:/usr/bin:/bin:/etc:/sbin:/usr/sbin:/usr/local/games:/usr/games:.:/home/rdm/bin:/home/vlb/projex/ptf/bin PERL_BADLANG (unset) SHELL=/ulb/tcsh ```