Subject: snmpconf Recommendations for Policy Language Implementation

From: Ray Byler <[email-masked]>
Date: Mon, 2 Apr 2001 10:54:48 -0400

I would like to make some recommendations for the
policy language.

1.  Nested comments should be allowed.

2.  Our implementation of sprintf(), unlike the C
    version, should make sure that the number of
    format specifiers in the format string matches
    the number of corresponding arguments.  Our version
    of sprintf(), unlike the C version (which is call
    by value), should be call by reference (to match the rest of
    the policy language). 
    
3.  The order of evaluation of arguments to function calls 
    should be right-to-left.  This is unspecified in C.
    Right-to-left matches the gcc and Turbo C implementations.
    The following test program demonstrates how different
    compilers evaluate arguments.
    
    Ray Byler    

/* 
    We are supposed to implement sprintf() for the policy
    language as defined in C.  The problem is that 
    C says "the order of evaluation
    of arguments is unspecified".  This can produce some
    peculiar results.  The following test program demonstates
    this for printf (sprintf is the same).  

*/   

#include <stdio.h>

/* Since variables in the policy language are all in
 * the same scope they will all be globals.
 */
 
int a = 7;

main(){

     printf("%d %d %d %d %d %d %d\n", a++, a++, a++, a, a--, a--, a--);
     printf("final: %d\n\n", a);

     printf("%d %d %d\n", a++, a++, a++);
     printf("final: %d\n\n", a);

}

/*
    gcc and Turbo C evaluate arguments from right to left.

6 5 4 4 5 6 7
final: 7

9 8 7
final: 10

    Microcrap's Visual C++ defers action until after the function call is complete.

7 7 7 7 7 7 7
final: 7

7 7 7
final: 10

    HP's cc evaluates arguments from left to right.
    
7 8 9 10 10 9 8
final: 7

7 8 9
final: 10

*/

---

From: Pablo Halpern <[email-masked]>
Date: Mon, 02 Apr 2001 12:16:16 -0400

>1.  Nested comments should be allowed.

C doesn't allow them, nor does C++. This doesn't seem like a particularly 
worthwhile place to diverge from the base language.

>     by value), should be call by reference (to match the rest of

Why do you need call by reference in sprintf?  The & notation in the 
description of functions means that the argument may be modified. sprintf() 
doesn't modify any arguments.

>     compilers evaluate arguments.

Again, I don't see this as a particularly worthwhile place to deviate from 
C or C++.
The example uses arguments with excessively interdependent side-effects. I 
don't see that we need to tie the hands of the implementor in order to make 
such things work consistently.

>     gcc and Turbo C evaluate arguments from right to left.

- Pablo
----------------------------------------------------------------------
Pablo Halpern                      http://www.halpernwightsoftware.com
[email-masked]