how can I remove all the comments in my c program.

V

Vellingiri Arul

Dear Friends,
using The Ruby how can I remove all the comments in my c program.
For example I have mentioned c program ,that may be ruby program
for your purpose you assume.
I have tried to do using the regular expression.
But I was unable to find the anser for this.


Please any one tell me.

By
Vellingiri.
 
S

Sebastian Hungerecker

Vellingiri said:
Dear Friends,
using The Ruby how can I remove all the comments in my c program.
For example I have mentioned c program ,that may be ruby program
for your purpose you assume.
I have tried to do using the regular expression.
But I was unable to find the anser for this.

The most simple regexen would be %r(//.*$) to match single line comments
and %r(/\*.*?\*/)m to match multiline comments, but these will give you some
false positives - for example, when you use // or /* inside a string.
If you want something that works reliably, you would need to use a C-parser
rather than regular expressions.


HTH,
Sebastian
 
V

Vellingiri Arul

Sebastian said:
The most simple regexen would be %r(//.*$) to match single line comments
and %r(/\*.*?\*/)m to match multiline comments, but these will give you
some
false positives - for example, when you use // or /* inside a string.
If you want something that works reliably, you would need to use a
C-parser
rather than regular expressions.


HTH,
Sebastian

Hai,
very very thank you.
I wil try to implement.


by
vellingiri.
 
O

On Web

Vellingiri Arul said:
Dear Friends,
using The Ruby how can I remove all the comments in my c program.
For example I have mentioned c program ,that may be ruby program
for your purpose you assume.
I have tried to do using the regular expression.
But I was unable to find the anser for this.

Why would anyone want to remove the comments from a program?

Paul
 
M

Marcin Raczkowski

Vellingiri Arul said:
Dear Friends,
using The Ruby how can I remove all the comments in my c program.
For example I have mentioned c program ,that may be ruby program
for your purpose you assume.
I have tried to do using the regular expression.
But I was unable to find the anser for this.

Why would anyone want to remove the comments from a program?

Paul
Please any one tell me.

By
Vellingiri.
becouse they have to release it as open source becouse of GPL or other
OS license and they want to make imposible to actually use that code by
striping comments and obscuring code.
 
A

ara.t.howard

Dear Friends,
using The Ruby how can I remove all the comments in my c program.
For example I have mentioned c program ,that may be ruby program
for your purpose you assume.
I have tried to do using the regular expression.
But I was unable to find the anser for this.


Please any one tell me.

i'd start with c's own preprocessor and go from there:

cfp:~ > cat a.c
/* comment be gone */
main(){ printf("%i\n", (int)(0.55 * 100)); }


cfp:~ > cpp a.c
# 1 "a.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "a.c"

main(){ printf("%i\n", (int)(0.55 * 100)); }


cfp:~ > cpp -P a.c
main(){ printf("%i\n", (int)(0.55 * 100)); }

it already knows how to strip comments.

a @ http://drawohara.com/
 
P

Peter Hickman

Marcin said:
becouse they have to release it as open source becouse of GPL or other
OS license and they want to make imposible to actually use that code
by striping comments and obscuring code.

Can we have the name of the company / project please. I wish to add it
to my list of things to avoid.
 
K

Konrad Meyer

--nextPart1709184.N4EHa9TSQk
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Quoth Marcin Raczkowski:
becouse they have to release it as open source becouse of GPL or other=20
OS license and they want to make imposible to actually use that code by=20
striping comments and obscuring code.

Umm... That's illegal, by terms of the GPL. The GPL defines source code as
the preferred form for modification. Intentionally obfuscated code isn't
the preferred form for modification. So while it's technically "source
code", it isn't according to the definition in the GPL, and thus they're
violating the license by doing that.

=2D-=20
Konrad Meyer <[email protected]> http://konrad.sobertillnoon.com/

--nextPart1709184.N4EHa9TSQk
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQBG8WiUCHB0oCiR2cwRAnTYAJ9dcx+xWN1llFbEKcIfrdqpHUWehQCfXoN2
HgZWPQ3T5ZZfNj0Wjsa6v94=
=jd/C
-----END PGP SIGNATURE-----

--nextPart1709184.N4EHa9TSQk--
 
M

Marcin Raczkowski

Konrad said:
Quoth Marcin Raczkowski:

Umm... That's illegal, by terms of the GPL. The GPL defines source code as
the preferred form for modification. Intentionally obfuscated code isn't
the preferred form for modification. So while it's technically "source
code", it isn't according to the definition in the GPL, and thus they're
violating the license by doing that.
well, i had "pleasure" of having internship in company which policy was
- use only MIT/BSD or LGPL as liblary, we won't pay for any licenses.
If you HAVE to use GPL make sure your changes are not documented, and
you use variable names like a,b,c and function names like fa fb etc.

while it's illegal to obscure code that's covered by gpl, if you write
code that extends it, you can argue it's your programming style, code
like this even not technically obfuscated is useless.

GPL can't force you to write documentation or make sefl-documenting code.
 
O

On Web

Marcin Raczkowski said:
snip

well, i had "pleasure" of having internship in company which policy was -
use only MIT/BSD or LGPL as liblary, we won't pay for any licenses.
If you HAVE to use GPL make sure your changes are not documented, and you
use variable names like a,b,c and function names like fa fb etc.

while it's illegal to obscure code that's covered by gpl, if you write
code that extends it, you can argue it's your programming style, code like
this even not technically obfuscated is useless.

GPL can't force you to write documentation or make sefl-documenting code.

Not quite the same thing as taking out what's already there. I really hope
the name of this company comes to light so they can get the negative
response they deserve.

Paul
 
T

Todd Benson

Dear Friends,
using The Ruby how can I remove all the comments in my c program.
For example I have mentioned c program ,that may be ruby program
for your purpose you assume.
I have tried to do using the regular expression.
But I was unable to find the anser for this.

Please try to meet your helpers half way.

Thanks,

Todd
 
C

Chris Carter

Not quite the same thing as taking out what's already there. I really hope
the name of this company comes to light so they can get the negative
response they deserve.

Paul

Nowhere did the OP state that this is the reason. Someone else threw
that out. There may be a legitimate reason for this.
 
P

Phlip

Not quite the same thing as taking out what's already there. I really hope
the name of this company comes to light so they can get the negative
response they deserve.

Worshipping comments is an intermediate, not advanced, behavior.

Comments have plenty of legitimate reasons to disappear, not least of which
is comments written only to satisfy some perverse mandated code rules.
 
M

Marcin Raczkowski

well, i guess this flamewar is becouse of me, so... it's of course
possible that someone want to remove all the comments from code for some
strange reason (i don't understand why tho), i might have biased view
becouse of my internship ... but tell me seriously ...


Worshipping comments is an intermediate, not advanced, behavior.
i don't understand this statement... but if it means what i think it
means you are seriously wrong, comments are more important the better
you are becouse more advenced programmers tend to use lots of idioms and
write optimized but not easilly readable code
Comments have plenty of legitimate reasons to disappear, not least of
which is comments written only to satisfy some perverse mandated code
rules.

i understand NOT writing comments, i do it myself often ... but if you
already have them in C code ... then why remove them?
if you compile code the'lll disapear anyway.. i doubt he works on
project that's source code is larger then 10mb compresed (and source
files compress with 90% ratio) so size is probably not the problem euther...

Philip could you tell me one legitimate reason to remove comments from c
code?
 
P

Peter Hickman

Marcin said:
i don't understand this statement... but if it means what i think it
means you are seriously wrong, comments are more important the better
you are becouse more advenced programmers tend to use lots of idioms
and write optimized but not easilly readable code

Some programmers seem to think that comments are an excuse for badly
written code. Well written code should be readable to a programmer
proficient in the language in question, this means that the need for
comments is reduced. People who insist on comments for everything tend
not to be good programmers. People who do not write any comments are
idiots no matter how advanced they are. There is always a need for
comments, it just depends on the degree.

As to idiomatic code, if you are an X programmer you should be familiar
with the idioms, if not learn some more. Also what is called idiomatic
depends on you background, ++x could be considered an idiom if your
background was perhaps COBOL, FORTRAN or LISP. Do you really expect such
code to be commented just in case someone isn't familiar with the 'idiom'?
i understand NOT writing comments, i do it myself often ... but if you
already have them in C code ... then why remove them?
if you compile code the'lll disapear anyway.. i doubt he works on
project that's source code is larger then 10mb compresed (and source
files compress with 90% ratio) so size is probably not the problem
euther...

Philip could you tell me one legitimate reason to remove comments from
c code?

The comments might be wrong! Comments tend not to be updated with the
same rigour as the code. It is sometimes better to throw the comments
out and make the programmer read the code to determine what it is doing
than be led astray by badly written comments. The code is the authority
as to what the program is doing, the comments are just commentary and
cannot affect the execution of the code. Of course the *best* course of
action is to completely rewrite the comments but if you can't do that
then I would recommend removing comments that serve only to confuse the
programmer.
 
P

Paul Knight

[C]ould you tell me one legitimate reason to remove comments from c
code?

Perhaps the original poster is going to run some custom code metrics
or code analysis, but wants to get rid of comments first.

Perhaps the original poster is going to annotate the code in a
different way, by surrounding it with prose, and the comments would
obfuscate rather than illuminate.

Perhaps it's for golfing.

Perhaps it's for an art project. Or an illustration for an argument.

Perhaps the original poster hasn't thought it all the way through.

Perhaps it's something dark, sinister, and nefarious. But perhaps not.

Perhaps the original poster could respond?

--Paulymer
 
V

Vellingiri Arul

Paul said:
[C]ould you tell me one legitimate reason to remove comments from c
code?

Perhaps the original poster is going to run some custom code metrics
or code analysis, but wants to get rid of comments first.

Perhaps the original poster is going to annotate the code in a
different way, by surrounding it with prose, and the comments would
obfuscate rather than illuminate.

Perhaps it's for golfing.

Perhaps it's for an art project. Or an illustration for an argument.

Perhaps the original poster hasn't thought it all the way through.

Perhaps it's something dark, sinister, and nefarious. But perhaps not.

Perhaps the original poster could respond?

--Paulymer
Hello,
What do you want?Why are you scolding me like that.
If we are asking only doubts,If you know tell yes.otherwise you tell no.
Don't speak nonsence others.
ok.

by
velligniri.
 
P

Paul Knight

Paul said:
[C]ould you tell me one legitimate reason to remove comments from c
code?

Perhaps the original poster is going to run some custom code metrics
or code analysis, but wants to get rid of comments first.

Perhaps the original poster is going to annotate the code in a
different way, by surrounding it with prose, and the comments would
obfuscate rather than illuminate.

Perhaps it's for golfing.

Perhaps it's for an art project. Or an illustration for an argument.

Perhaps the original poster hasn't thought it all the way through.

Perhaps it's something dark, sinister, and nefarious. But perhaps
not.

Perhaps the original poster could respond?

--Paulymer
Hello,
What do you want?Why are you scolding me like that.
If we are asking only doubts,If you know tell yes.otherwise you
tell no.
Don't speak nonsence others.
ok.

by
velligniri.

We're curious why you want to strip out comments, and whether it may
or may not be a good idea. I wanted to suggest to several others that
there are legitimate reasons, though a few of them might be slightly
misguided. Perhaps if you explained why you want to get rid of the
comments, it would clear up some of the messages in this thread.

--Paulymer
 
V

Vellingiri Arul

Paul said:
We're curious why you want to strip out comments, and whether it may
or may not be a good idea. I wanted to suggest to several others that
there are legitimate reasons, though a few of them might be slightly
misguided. Perhaps if you explained why you want to get rid of the
comments, it would clear up some of the messages in this thread.

--Paulymer

Hello Friends,
I am also working in software company.
You ask know why are removing the comments in your c program.
For needness I want to remove all the comments and also I want to align
all the program coding lines.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top