Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C Style commenting
#20
Oracle,

At first glance, your challenge to remove comments from C code looks relatively easy. I haven't needed to use C in about 6 years, so I dug up some of my old C programs and took a look.

The first question in my mind is: Why would you want to strip the comments from a C program anyway? Is this a practical requirement or just an exercise?

While scanning over 100 C programs, I couldn't find the // prefix for on-line comments. I only found the leading /* and the trailing */ even if the comment was only on a single line. Are you sure the // option exists on all versions of C?

Anyway, my review of the programs came up with the following sticky considerations:

1) It's possible that /* or */ or // could appear inside of a quoted string, and some quoted strings are delimited by double quotes (") and others by single quotes ('). So every time the program finds one of these supposed comment delimeters, it would have to do several scans to make sure that they were not found within quoted strings, which of course would have to be ignored. This is not as easy as it sounds. Watch out, 'cause the comments themselves could contain either of the quotes or even embedded delimiters themselves.

2) An absolute "must" requirement is that the C source code has already been successfully compiled. You can appreciate that if the source code has errors, then the comment removing program will go bananas. In any event, the program will have to detect certain fatal errors, like a multi-line comment that has no subsequent */ terminator.

3) Another "must" is to successfully compile the new uncommented code and then compare the object code to the original. If they don't match, then the comment remover doesn't work.

Since you mentioned "C style" programs, perhaps the program will have to ask the user up front what comment delimeters he wants to use. Maybe this can be on a little parameter file as input.

In summary, if you have a practical use for this program, I'd be interested in taking a crack at it. If it's just an exercise, I'll pass.
*****
Reply


Messages In This Thread
C Style commenting - by oracle - 01-01-2004, 03:18 AM
C Style commenting - by red_Marvin - 01-01-2004, 03:35 AM
C Style commenting - by oracle - 01-01-2004, 04:16 AM
C Style commenting - by adosorken - 01-01-2004, 05:18 AM
C Style commenting - by Zack - 01-01-2004, 05:52 AM
C Style commenting - by oracle - 01-01-2004, 06:08 AM
C Style commenting - by Plasma - 01-01-2004, 06:16 AM
C Style commenting - by oracle - 01-01-2004, 06:18 AM
C Style commenting - by Plasma - 01-01-2004, 07:45 AM
C Style commenting - by adosorken - 01-01-2004, 08:02 AM
C Style commenting - by Agamemnus - 01-01-2004, 08:29 AM
C Style commenting - by adosorken - 01-01-2004, 08:45 AM
C Style commenting - by Plasma - 01-01-2004, 10:17 AM
C Style commenting - by Anonymous - 01-01-2004, 10:31 AM
C Style commenting - by adosorken - 01-01-2004, 10:46 AM
C Style commenting - by Zack - 01-01-2004, 08:39 PM
C Style commenting - by wildcard - 01-01-2004, 08:46 PM
C Style commenting - by Zack - 01-01-2004, 08:47 PM
C Style commenting - by Fling-master - 01-01-2004, 08:49 PM
C Style commenting - by Moneo - 01-02-2004, 06:52 AM
C Style commenting - by na_th_an - 01-02-2004, 06:56 AM
C Style commenting - by Moneo - 01-02-2004, 07:06 AM
C Style commenting - by na_th_an - 01-02-2004, 07:13 AM
C Style commenting - by Moneo - 01-02-2004, 07:40 AM
C Style commenting - by na_th_an - 01-02-2004, 07:48 AM
C Style commenting - by Moneo - 01-02-2004, 07:55 AM
C Style commenting - by oracle - 01-02-2004, 08:06 AM
C Style commenting - by na_th_an - 01-02-2004, 08:26 AM
C Style commenting - by oracle - 01-02-2004, 10:01 AM
C Style commenting - by na_th_an - 01-02-2004, 10:27 AM
C Style commenting - by oracle - 01-02-2004, 10:30 AM
C Style commenting - by adosorken - 01-02-2004, 10:31 AM
C Style commenting - by Mango - 01-02-2004, 03:37 PM
C Style commenting - by Rhiannon - 01-02-2004, 04:46 PM
C Style commenting - by LooseCaboose - 01-04-2004, 12:30 PM
C Style commenting - by Agamemnus - 01-05-2004, 01:10 AM
C Style commenting - by oracle - 01-06-2004, 03:59 AM
C Style commenting - by Agamemnus - 01-06-2004, 08:39 PM
C Style commenting - by oracle - 01-07-2004, 03:33 AM
C Style commenting - by Agamemnus - 01-07-2004, 07:02 AM
C Style commenting - by oracle - 01-07-2004, 08:23 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)