cdecl test cases

Discussion in 'C Programming' started by Tor Rustad, Mar 21, 2005.

  1. Tor Rustad

    Tor Rustad Guest

    Did a fun project some years ago.. a cdecl, but never really tested it.

    Here are some test cases I just tried:

    cdecl> char **argv;
    cdecl> argv is pointer to pointer to char
    Looks ok

    cdecl> int (*daytab)[13];
    cdecl> daytab is pointer to array [13] of int
    Looks ok

    cdecl> int *daytab[13];
    cdecl> daytab is array [13] of pointer to int
    Looks ok

    cdecl> void *comp();
    cdecl> comp is function returning pointer to void
    Looks ok

    cdecl> char (*(*x())[])();
    cdecl> x is function returning pointer to array of pointer to function
    returning char
    Looks ok

    cdecl> char (*(*x[3])())[5];
    cdecl> x is array [3] of pointer to function returning pointer to array
    [5] of char
    Looks ok

    cdecl> char* const *(*next)();
    cdecl> next is pointer to function returning pointer to (read-only)
    pointer to char
    Parse error: ";" at line 255. Hint: Not a valid type.
    Looks ok, except for the parse error.

    cdecl> char **(c[10])(int **p);
    cdecl> c is array [10] of function returning pointer to pointer to char
    Looks ok

    cdecl> void (*signal(int sig, void (*func)(int)))(int);
    cdecl> signal is function returning pointer to void
    cdecl> void (*signal(int, void (*)(int)))(int);
    cdecl> signal is function returning pointer to void
    Not ok

    Did I miss something here, or do people agree with the above?
    (I don't have another cdecl to cross-check with)

    Does someone have ideas for more test-cases?

    --
    Tor <torust AT online DOT no>
    Tor Rustad, Mar 21, 2005
    #1
    1. Advertising

  2. Tor Rustad

    tigervamp Guest

    Tor Rustad wrote:
    > Did a fun project some years ago.. a cdecl, but never really tested

    it.
    >
    > Here are some test cases I just tried:
    >
    > cdecl> char **argv;
    > cdecl> argv is pointer to pointer to char
    > Looks ok
    >
    > cdecl> int (*daytab)[13];
    > cdecl> daytab is pointer to array [13] of int
    > Looks ok
    >
    > cdecl> int *daytab[13];
    > cdecl> daytab is array [13] of pointer to int
    > Looks ok
    >
    > cdecl> void *comp();
    > cdecl> comp is function returning pointer to void
    > Looks ok
    >
    > cdecl> char (*(*x())[])();
    > cdecl> x is function returning pointer to array of pointer to

    function
    > returning char
    > Looks ok
    >
    > cdecl> char (*(*x[3])())[5];
    > cdecl> x is array [3] of pointer to function returning pointer to

    array
    > [5] of char
    > Looks ok
    >
    > cdecl> char* const *(*next)();
    > cdecl> next is pointer to function returning pointer to (read-only)
    > pointer to char
    > Parse error: ";" at line 255. Hint: Not a valid type.
    > Looks ok, except for the parse error.
    >
    > cdecl> char **(c[10])(int **p);
    > cdecl> c is array [10] of function returning pointer to pointer to

    char
    > Looks ok
    >
    > cdecl> void (*signal(int sig, void (*func)(int)))(int);
    > cdecl> signal is function returning pointer to void
    > cdecl> void (*signal(int, void (*)(int)))(int);
    > cdecl> signal is function returning pointer to void
    > Not ok


    My cdecl shows:

    cdecl> explain void (*signal(int sig, void (*func)(int)))(int);
    syntax error

    I don't think the version of cdecl that I have handles multiple
    identifiers in a single declaration (signal and func in this case).

    cdecl> explain void (*signal(int, void (*)(int)))(int);
    declare signal as function (int, pointer to function (int) returning
    void) returning pointer to function (int) returning void

    Look good.

    > Did I miss something here, or do people agree with the above?
    > (I don't have another cdecl to cross-check with)
    >
    > Does someone have ideas for more test-cases?


    The version I have is very capable and featureful and supports readline
    if you have it. It was written for Linux but should be easy to port to
    similiar systems. You can download the source code package, which
    comes with a mini test quite, at:
    http://www.ibiblio.org/pub/Linux/devel/lang/c/cdecl-2.5.tar.gz.

    > --
    > Tor <torust AT online DOT no>


    Rob Gamble
    tigervamp, Mar 22, 2005
    #2
    1. Advertising

  3. Tor Rustad

    CBFalconer Guest

    Tor Rustad wrote:
    >
    > Did a fun project some years ago.. a cdecl, but never really tested it.
    >
    > Here are some test cases I just tried:
    >
    > cdecl> char **argv;
    > cdecl> argv is pointer to pointer to char
    > Looks ok
    >
    > cdecl> int (*daytab)[13];
    > cdecl> daytab is pointer to array [13] of int
    > Looks ok
    >
    > cdecl> int *daytab[13];
    > cdecl> daytab is array [13] of pointer to int
    > Looks ok
    >
    > cdecl> void *comp();
    > cdecl> comp is function returning pointer to void
    > Looks ok
    >
    > cdecl> char (*(*x())[])();
    > cdecl> x is function returning pointer to array of pointer to function
    > returning char
    > Looks ok
    >
    > cdecl> char (*(*x[3])())[5];
    > cdecl> x is array [3] of pointer to function returning pointer to array
    > [5] of char
    > Looks ok
    >
    > cdecl> char* const *(*next)();
    > cdecl> next is pointer to function returning pointer to (read-only)
    > pointer to char
    > Parse error: ";" at line 255. Hint: Not a valid type.
    > Looks ok, except for the parse error.
    >
    > cdecl> char **(c[10])(int **p);
    > cdecl> c is array [10] of function returning pointer to pointer to char
    > Looks ok
    >
    > cdecl> void (*signal(int sig, void (*func)(int)))(int);
    > cdecl> signal is function returning pointer to void
    > cdecl> void (*signal(int, void (*)(int)))(int);
    > cdecl> signal is function returning pointer to void
    > Not ok
    >
    > Did I miss something here, or do people agree with the above?
    > (I don't have another cdecl to cross-check with)
    >
    > Does someone have ideas for more test-cases?


    Here are the results on my system

    [1] c:\c\junk>cdecl cdecl.c
    declare argv as pointer to pointer to char
    declare daytab as pointer to array 13 of int
    declare daytab as array 13 of pointer to int
    declare comp as function returning pointer to void
    declare x as function returning pointer to array of pointer to
    function returning char
    declare x as array 3 of pointer to function returning pointer to
    array 5 of char
    declare next as pointer to function returning pointer to const
    pointer to char
    parse error
    parse error
    declare signal as function (int, pointer to function (int)
    returning void) returning pointer to function (int) returning void

    [1] c:\c\junk>cat cdecl.c
    explain char **argv;
    explain int (*daytab)[13];
    explain int *daytab[13];
    explain void *comp();
    explain char (*(*x())[])();
    explain char (*(*x[3])())[5];
    explain char* const *(*next)();
    explain char **(c[10])(int **p);
    explain void (*signal(int sig, void (*func)(int)))(int);
    explain void (*signal(int, void (*)(int)))(int);


    --
    "I conclude that there are two ways of constructing a software
    design: One way is to make it so simple that there are obviously
    no deficiencies and the other way is to make it so complicated
    that there are no obvious deficiencies." -- C. A. R. Hoare
    CBFalconer, Mar 22, 2005
    #3
  4. Tor Rustad

    Tor Rustad Guest

    "CBFalconer" <> wrote in message

    <snip>

    > Here are the results on my system
    >
    > [1] c:\c\junk>cdecl cdecl.c
    > declare argv as pointer to pointer to char
    > declare daytab as pointer to array 13 of int
    > declare daytab as array 13 of pointer to int
    > declare comp as function returning pointer to void
    > declare x as function returning pointer to array of pointer to
    > function returning char
    > declare x as array 3 of pointer to function returning pointer to
    > array 5 of char
    > declare next as pointer to function returning pointer to const
    > pointer to char
    > parse error
    > parse error
    > declare signal as function (int, pointer to function (int)
    > returning void) returning pointer to function (int) returning void
    >
    > [1] c:\c\junk>cat cdecl.c
    > explain char **argv;
    > explain int (*daytab)[13];
    > explain int *daytab[13];
    > explain void *comp();
    > explain char (*(*x())[])();
    > explain char (*(*x[3])())[5];
    > explain char* const *(*next)();
    > explain char **(c[10])(int **p);
    > explain void (*signal(int sig, void (*func)(int)))(int);
    > explain void (*signal(int, void (*)(int)))(int);


    Thanks! Does

    explain char **(c[10])(int **);

    also give a parse error?

    --
    Tor <torust AT online DOT no>
    Tor Rustad, Mar 22, 2005
    #4
  5. Tor Rustad

    Tor Rustad Guest

    "tigervamp" <> wrote in message

    <snip>

    > My cdecl shows:
    >
    > cdecl> explain void (*signal(int sig, void (*func)(int)))(int);
    > syntax error
    >
    > I don't think the version of cdecl that I have handles multiple
    > identifiers in a single declaration (signal and func in this case).


    Right, IMHO that would be useful for cdecl to handle.

    > cdecl> explain void (*signal(int, void (*)(int)))(int);
    > declare signal as function (int, pointer to function (int) returning
    > void) returning pointer to function (int) returning void
    >
    > Look good.


    Yup, agreed.

    > > Does someone have ideas for more test-cases?

    >
    > The version I have is very capable and featureful and supports

    readline
    > if you have it.


    Windows box here, which lack readline, yacc and flex!!

    > It was written for Linux but should be easy to port to
    > similiar systems. You can download the source code package, which
    > comes with a mini test quite, at:
    > http://www.ibiblio.org/pub/Linux/devel/lang/c/cdecl-2.5.tar.gz.


    Took a look at the package, and it was far more advanced than my
    little C utility (850 lines of yacc code vs 200 lines of C parser code).
    For now, I only want to get 'explain' working with C89 (and C99).

    I see one main thing for me to add then, and that is to parse/display
    the argument list of functions... <g>

    --
    Tor <torust AT online DOT no>
    Tor Rustad, Mar 22, 2005
    #5
  6. Tor Rustad

    CBFalconer Guest

    Tor Rustad wrote:
    >
    > "CBFalconer" <> wrote in message
    >
    > <snip>
    >
    > > Here are the results on my system
    > >
    > > [1] c:\c\junk>cdecl cdecl.c
    > > declare argv as pointer to pointer to char
    > > declare daytab as pointer to array 13 of int
    > > declare daytab as array 13 of pointer to int
    > > declare comp as function returning pointer to void
    > > declare x as function returning pointer to array of pointer to
    > > function returning char
    > > declare x as array 3 of pointer to function returning pointer to
    > > array 5 of char
    > > declare next as pointer to function returning pointer to const
    > > pointer to char
    > > parse error
    > > parse error
    > > declare signal as function (int, pointer to function (int)
    > > returning void) returning pointer to function (int) returning void
    > >
    > > [1] c:\c\junk>cat cdecl.c
    > > explain char **argv;
    > > explain int (*daytab)[13];
    > > explain int *daytab[13];
    > > explain void *comp();
    > > explain char (*(*x())[])();
    > > explain char (*(*x[3])())[5];
    > > explain char* const *(*next)();
    > > explain char **(c[10])(int **p);
    > > explain void (*signal(int sig, void (*func)(int)))(int);
    > > explain void (*signal(int, void (*)(int)))(int);

    >
    > Thanks! Does
    >
    > explain char **(c[10])(int **);
    >
    > also give a parse error?


    [1] c:\dnld\scratch>explain char **(c[10])(int **);
    declare c as array 10 of function (pointer to pointer to int)
    returning pointer
    to pointer to char

    --
    "I conclude that there are two ways of constructing a software
    design: One way is to make it so simple that there are obviously
    no deficiencies and the other way is to make it so complicated
    that there are no obvious deficiencies." -- C. A. R. Hoare
    CBFalconer, Mar 22, 2005
    #6
  7. Version 2.5 source, test cases, and executable for Winblows:

    <ftp://ftp.quitt.net/C/cdecl.zip>


    --
    #include <standard.disclaimer>
    _
    Kevin D Quitt USA 91387-4454 96.37% of all statistics are made up
    Per the FCA, this address may not be added to any commercial mail list
    Kevin D. Quitt, Mar 22, 2005
    #7
  8. Tor Rustad

    CBFalconer Guest

    "Kevin D. Quitt" wrote:
    >
    > Version 2.5 source, test cases, and executable for Winblows:
    >
    > <ftp://ftp.quitt.net/C/cdecl.zip>


    Minor detail - that has been zipped with something outlandish, and
    neither unzip (info-zip 5.51) nor pkunzip (katz 2.50) can extract
    it.

    --
    "I conclude that there are two ways of constructing a software
    design: One way is to make it so simple that there are obviously
    no deficiencies and the other way is to make it so complicated
    that there are no obvious deficiencies." -- C. A. R. Hoare
    CBFalconer, Mar 23, 2005
    #8
  9. On Wed, 23 Mar 2005 05:05:29 GMT, CBFalconer <> wrote:
    >Minor detail - that has been zipped with something outlandish, and
    >neither unzip (info-zip 5.51) nor pkunzip (katz 2.50) can extract
    >it.


    My apologies. I used PKZIP originally; rezipped with gnu zip 2.3.


    --
    #include <standard.disclaimer>
    _
    Kevin D Quitt USA 91387-4454 96.37% of all statistics are made up
    Per the FCA, this address may not be added to any commercial mail list
    Kevin D. Quitt, Mar 24, 2005
    #9
  10. Tor Rustad

    CBFalconer Guest

    "Kevin D. Quitt" wrote:
    > CBFalconer <> wrote:
    >
    >> Minor detail - that has been zipped with something outlandish, and
    >> neither unzip (info-zip 5.51) nor pkunzip (katz 2.50) can extract it.

    >
    > My apologies. I used PKZIP originally; rezipped with gnu zip 2.3.


    Of course you snipped the URL, so now I don't know where to go for
    it any more :)

    --
    "If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers." - Keith Thompson
    CBFalconer, Mar 25, 2005
    #10
  11. Tor Rustad

    CBFalconer Guest

    CBFalconer wrote:
    > "Kevin D. Quitt" wrote:
    >> CBFalconer <> wrote:
    >>
    >>> Minor detail - that has been zipped with something outlandish, and
    >>> neither unzip (info-zip 5.51) nor pkunzip (katz 2.50) can extract it.

    >>
    >> My apologies. I used PKZIP originally; rezipped with gnu zip 2.3.

    >
    > Of course you snipped the URL, so now I don't know where to go for
    > it any more :)


    And now I found the old URL, redownloaded it, and you omitted the
    makefile!

    --
    "If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers." - Keith Thompson
    CBFalconer, Mar 25, 2005
    #11
  12. Tor Rustad

    Michael Mair Guest

    CBFalconer wrote:
    > CBFalconer wrote:
    >
    >>"Kevin D. Quitt" wrote:
    >>
    >>>CBFalconer <> wrote:
    >>>
    >>>
    >>>>Minor detail - that has been zipped with something outlandish, and
    >>>>neither unzip (info-zip 5.51) nor pkunzip (katz 2.50) can extract it.
    >>>
    >>>My apologies. I used PKZIP originally; rezipped with gnu zip 2.3.

    >>
    >>Of course you snipped the URL, so now I don't know where to go for
    >>it any more :)

    >
    >
    > And now I found the old URL, redownloaded it, and you omitted the
    > makefile!


    My, you are one hard to satisfy customer...
    Next time he will have to go for the closet in the basement ;-)


    Cheers
    Michael
    --
    E-Mail: Mine is an /at/ gmx /dot/ de address.
    Michael Mair, Mar 25, 2005
    #12
  13. <ftp://ftp.quitt.net/c/cdecl-2.5.zip>

    *sigh*


    --
    #include <standard.disclaimer>
    _
    Kevin D Quitt USA 91387-4454 96.37% of all statistics are made up
    Per the FCA, this address may not be added to any commercial mail list
    Kevin D. Quitt, Mar 28, 2005
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James Brown [MVP]

    help with 'left-right' cdecl rule

    James Brown [MVP], Feb 13, 2006, in forum: C Programming
    Replies:
    6
    Views:
    387
    Ben Bacarisse
    Feb 14, 2006
  2. Replies:
    5
    Views:
    404
  3. shanti

    cdecl

    shanti, Jun 3, 2007, in forum: C Programming
    Replies:
    12
    Views:
    1,021
    jaysome
    Jun 8, 2007
  4. Amandil

    what is cdecl

    Amandil, Mar 4, 2008, in forum: C Programming
    Replies:
    11
    Views:
    787
    Robbie Hatley
    Mar 5, 2008
  5. David Mitchell
    Replies:
    10
    Views:
    245
Loading...

Share This Page