#1 ANSI compliant C?

closed
nobody
None
5
2007-11-22
2007-11-06
Corey Stup
No

Do you wish for MJSON to be ANSI compliant? If so, its not currently.

A couple issues I saw:
Use of // for comments. GCC allows this, ANSI does not.
Local variables being declared after the start of a scope block.

The following lines with the current release (0.5) are in error (mostly due to variables being declared mid block)

"json.c", line 56.9: 1506-046 (S) Syntax error.
"json.c", line 86.9: 1506-046 (S) Syntax error.
"json.c", line 246.9: 1506-275 (S) Unexpected text 'enum' encountered.
"json.c", line 249.9: 1506-046 (S) Syntax error.
"json.c", line 270.9: 1506-275 (S) Unexpected text 'int' encountered.
"json.c", line 329.9: 1506-046 (S) Syntax error.
"json.c", line 331.9: 1506-046 (S) Syntax error.
"json.c", line 333.9: 1506-046 (S) Syntax error.
"json.c", line 334.9: 1506-046 (S) Syntax error.
"json.c", line 632.9: 1506-046 (S) Syntax error.
"json.c", line 634.9: 1506-046 (S) Syntax error.
"json.c", line 635.9: 1506-046 (S) Syntax error.
"json.c", line 636.9: 1506-046 (S) Syntax error.
"json.c", line 661.25: 1506-275 (S) Unexpected text 'char' encountered.
"json.c", line 821.25: 1506-275 (S) Unexpected text 'char' encountered.
"json.c", line 1185.9: 1506-046 (S) Syntax error.
"json.c", line 1186.9: 1506-046 (S) Syntax error.
"json.c", line 2182.17: 1506-046 (S) Syntax error.
"json.c", line 3076.9: 1506-275 (S) Unexpected text 'enum' encountered.
"json.c", line 3095.9: 1506-046 (S) Syntax error.
"json.c", line 4535.9: 1506-046 (S) Syntax error.

Discussion

  • Anonymous - 2007-11-06

    Logged In: YES
    user_id=1518475
    Originator: NO

    I've tested the code with GCC 4.1.3 with the --pedantic -Wall -Wextra --std=c99 flags and everything compiles flawlessly. What version of GCC are you running?

     
  • Corey Stup

    Corey Stup - 2007-11-07

    Logged In: YES
    user_id=300242
    Originator: YES

    I'm testing with a native IBM compiler (VisualAge C++) under C89 (xlc). ANSI/ISO (C89/C90) compliance seems to be a bit more portable for those of us that don't use gcc.

    Thanks!

     
  • Anonymous - 2007-11-07

    Logged In: YES
    user_id=1518475
    Originator: NO

    I've tested again with GCC 4.1.3 but this time with the --std=c89 flag and it also threw up a very long line of errors and warnings. Not nice.

    If you are willing to write a patch to make the code C89-compliant and if those changes don't affect the C99 compliance (which I believe they won't) then I would be happy to commit them.

     
  • Corey Stup

    Corey Stup - 2007-11-07

    Logged In: YES
    user_id=300242
    Originator: YES

    Attached are updated json.c and json.h with the comments migrated and the auto variable decl's directly following a scope block.

    File Added: json.h

     
  • Corey Stup

    Corey Stup - 2007-11-07

    Logged In: YES
    user_id=300242
    Originator: YES

    json.c attached.
    File Added: json.c

     
  • Anonymous - 2007-11-08

    Logged In: YES
    user_id=1518475
    Originator: NO

    I've tweaked most of the code to clean the C89 issues but some issues still remain. There is the issue of the swprintf usage in json.c:995, a couple of issues regarding the usage of the %ls flag in printf and a couple of minor variable declaration problems. Other than that I believe there is no other problem.

    Please check out the code stored in the subversion repository. It is more up to date and has less bugs.

     
  • Corey Stup

    Corey Stup - 2007-11-08

    Logged In: YES
    user_id=300242
    Originator: YES

    Can you attach a tarball of the 2 files from the svn repo here? I don't use svn at home and so its not easy for me to actually checkout or delta against sourceforge. I miss the CVS interface. :)

    Thanks for taking a look at this. I was needing a quick and dirty JSON implementation and your simple, C, only-two-files-needed implementation was perfect. The only thing standing in my way was that it required C99, which seems iffy (even GCC doesn't support all C99 options correctly...)

     
  • Anonymous - 2007-11-08

    json.h

     
  • Anonymous - 2007-11-08

    Logged In: YES
    user_id=1518475
    Originator: NO

    File Added: json.h

     
  • Anonymous - 2007-11-08

    json.c

     
  • Anonymous - 2007-11-08

    Logged In: YES
    user_id=1518475
    Originator: NO

    File Added: json.c

     
  • Anonymous - 2007-11-08

    Logged In: YES
    user_id=1518475
    Originator: NO

    There you go :)

    I've uploaded the files you asked. I left the helper files out, as they don't offer any fundamental feature.

    Meanwhile I've updated the repository with an additional C89 clean-up. I do believe you would be better served if you accessed the files from the subversion repository. The project page's subversion WWW interface lets you do everything, including download whatever file you wish.

    Regarding the code, right now I believe there are only two issues separating us from C89 compliance. The first issue is printf()'s %ls flag which is used in a routine included in json_helper.c. That is pretty much irrelevant, as it's a small routine that I wrote mainly to use along in the library's debugging. The other issue is very relevant. I used the swprintf() function to help escape non-ASCII characters in json_escape() and it seems that that particular function isn't supported in C89. So it seems that in order to make this library C89-compliant we need to find another way to perform that task. What are your thoughts on this? Do you have any suggestion?

     
  • Corey Stup

    Corey Stup - 2007-11-08

    Logged In: YES
    user_id=300242
    Originator: YES

    I'll take a look at your updated files and see how to download individual files from the ViewSVN thing on SF. I thought it only allowed me to view, but that will be handy if theres a download function.

    As far as swprintf() is concerned, it appears to be part of the Standard C library as of C89. wchar.h is supported in C89 and from everything I can see, swprintf() is part of C89. So that may not be that much of a concern anyway. Its definitely supported on my system in C89 (AIX).

    %ls seems to non-compliant, but as you mentioned its just for a debugging routine.

    Thanks!

     
  • Anonymous - 2007-11-08

    Logged In: YES
    user_id=1518475
    Originator: NO

    That's good to hear. Nonetheless, things aren't exactly perfect yet. With the -std=c89 flag GCC still throws a few warnings regarding swprintf() and, at least to my not-familiar-with-C89 eyes, some bits look a bit fishy.

    So please keep me posted. Portability is very important, specially when things don't break down in shambles :D

     
  • Anonymous - 2007-11-22

    Logged In: YES
    user_id=1518475
    Originator: NO

    Closed due to lack of feedback.

     
  • Anonymous - 2007-11-22
    • status: open --> closed
     

Log in to post a comment.