Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: program which removes comments from C source |
| Date | 2011-06-13 19:23 -0700 |
| Organization | None to speak of |
| Message-ID | <lnips95ewx.fsf@nuthaus.mib.org> (permalink) |
| References | <a6268caf-18a8-4e8f-9b2e-433fc57397a8@j31g2000yqe.googlegroups.com> |
Ceriousmall <divadsmall@gmail.com> writes:
> I just need some feedback on this code. Its one of the K&R exercises.
>
> /* 2011/05 Ceriousmall. . . .
> * this program is code-named delcom and as such it deletes all
> comments from a C Program. . . . */
>
> #include <stdio.h>
>
> #define ASTR '*'
> #define BSLASH '/'
> #define FSLASH '\\'
You've defined BSLASH as a forward slash and FSLASH as a backslash.
> #define DBQTS '\"'
The backslash isn't necessary; you can just write '"'.
> #define SNQTS '\''
> #define SPC ' '
But really, what benefit do these macros give you? The abbrvtns r vry
tsr -- sorry, I mean the abbreviations are very terse -- and IMHO this:
line[i+1] == '*'
is much clearer than this:
line[i+1] == ASTR
or even this:
line[i+1] == ASTERISK
anyway. It's not as if the value of ASTR is ever going to change.
> #define IN 1 /* in a comment or quoted string*/
> #define OUT 0 /* outside of a comment or quoted string */
It might be clearer to define a variable that's true if you're inside a
comment or quoted string, false otherwise. Or define an enumerated
type.
Some things to consider:
C99 introduced // comments. Do you want to handle those?
A comment delimiter is also ignored if it appears in a character
constant or header name:
#include </*.h>
int c = '/*';
I'm afraid that's as far as I got. I might take another look later.
[snip]
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
program which removes comments from C source Ceriousmall <divadsmall@gmail.com> - 2011-06-13 18:20 -0700
Re: program which removes comments from C source Ceriousmall <divadsmall@gmail.com> - 2011-06-13 18:23 -0700
Re: program which removes comments from C source Keith Thompson <kst-u@mib.org> - 2011-06-13 19:23 -0700
Re: program which removes comments from C source Ceriousmall <divadsmall@gmail.com> - 2011-06-13 19:37 -0700
Re: program which removes comments from C source Ceriousmall <divadsmall@gmail.com> - 2011-06-13 19:41 -0700
Re: program which removes comments from C source Ian Collins <ian-news@hotmail.com> - 2011-06-14 14:57 +1200
Re: program which removes comments from C source Ceriousmall <divadsmall@gmail.com> - 2011-06-13 19:53 -0700
Re: program which removes comments from C source Ike Naar <ike@iceland.freeshell.org> - 2011-06-14 07:23 +0000
Re: program which removes comments from C source Ceriousmall <divadsmall@gmail.com> - 2011-06-14 14:15 -0700
Re: program which removes comments from C source Tim Rentsch <txr@alumni.caltech.edu> - 2011-06-14 16:30 -0700
csiph-web