[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: snmpconf Recommendations for Policy Language Implementation



At 10:54 AM 4/2/01 -0400, Ray Byler wrote:

>I would like to make some recommendations for the
>policy language.
>
>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.


>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).

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.

>
>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.

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.

>
>     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
>
>
>*/

- Pablo
----------------------------------------------------------------------
Pablo Halpern                      http://www.halpernwightsoftware.com
phalpern@newview.org