Function declaration and use 
Author Message
 Function declaration and use

Hello all,

I've been reading about user defined functions, and the extent to
which white space (or the lack of it) for source code formatting is
important to the awk interpreter.

I'm currently using a SCO version of nawk, which appears to use the
following rules:
The only place where white space is _not_ allowed is after the name of
a user defined function, when that function is called.
so
        my_func( "hello world" )      # this is OK
        my_func ( "hello world" )     # Produces an error

However, when an inbuilt function is called, this rule does not seem
to matter,
        n = index( "abc", "b" )             # this is OK
        n = index ( "abc", "b" )    # this is OK also

Similarly, when user defined functions are defined, white space is
also optional
function my_func( msg ) { print msg }   # this is OK
and
function my_func ( msg ) { print msg }  # and so is this

Am I compromising the portability of my awk code, by taking advantage
of the formatting which my awk interpreter will allow?

Thanks for any info,
--
Steve



Sun, 22 Apr 2001 03:00:00 GMT  
 Function declaration and use

[...]

% I'm currently using a SCO version of nawk, which appears to use the
% following rules:
% The only place where white space is _not_ allowed is after the name of
% a user defined function, when that function is called.
% so
%       my_func( "hello world" )      # this is OK
%       my_func ( "hello world" )     # Produces an error
%
% However, when an inbuilt function is called, this rule does not seem
% to matter,
%       n = index( "abc", "b" )             # this is OK
%       n = index ( "abc", "b" )    # this is OK also

[...]

% Am I compromising the portability of my awk code, by taking advantage
% of the formatting which my awk interpreter will allow?

All interpreters I've used work like this, however your best bet is
to track down a copy of _the awk language_ or the posix standard to see
what they allow, rather than hope that all interpreters work like yours.

On the other hand, I don't see how the space adds clarity in this case.
--

Patrick TJ McPhee
East York  Canada



Mon, 23 Apr 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Trouble using variables for function names in function declarations

2. Trouble using variables for function names in function declarations

3. Function Declaration and what to send

4. ASCIIZ limmits in Function declaration

5. Updated function declarations for SocketTools

6. Function Declaration by Template generation...

7. Clean function declaration

8. function declarations

9. question on function procedure declaration

10. Function declarations?

11. VHDL function declaration (variable)

12. Procedure/function specification/declarations

 

 
Powered by phpBB® Forum Software