C source code formatter: looking for a good one

Hi folls,

I'm looking for a good C source code formatter that eventually be able to strip out comments from the source.

thanks Enrico

Reply to
Enrico Migliore
Loading thread data ...

indent + a little perl-script does this for me.

--
42Bastian
Do not email to bastian42@yahoo.com, it's a spam-only account :-)
 Click to see the full signature
Reply to
42Bastian Schick

Are you thinking of some sort of automatic documentation tool? If so, have a look at

formatting link
.

Reply to
David Brown

Hi Enrico,

In the Win32 world, I use to write my source using a small freeware called "JFE".

In this editor, there is an automatic indent function for C/C++ (edit/operations/align C syntax). IMHO, this is a really good software you should try. (thanks to Jens Altmann !)

Regards Emmanuel.

Enrico Migliore wrote:

Reply to
Emmanuel Herbreteau

The C preprocessor strips comments out of your source code for you already. Look for the switch that enables preprocessor output and set it.

Regards Sergio Masci

formatting link
- optimising structured PIC BASIC compiler

Reply to
Sergio Masci

thanks Sergio, I did it: the preprocessor does strip out all comments but it adds also all header files.

Enrico

-- *********************************************************** * Enrico Migliore - Co-founder and Senior Software Engineer * * FATTI srl - GPRS - GSM - OSGi software * Via Donatello 48 - 200200 - Solaro - Milano - Italy *

formatting link
* * mail: snipped-for-privacy@fatti.com ***********************************************************

Reply to
Enrico Migliore

GNU indent will handle the formatting. To strip comments, see uncmntc.zip, available in source form at:

which will not handle trigraphs, nor multi-char char constants such as 'ab'. Strings are alright.

--
Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net)
   Available for consulting/temporary embedded and systems.
 Click to see the full signature
Reply to
CBFalconer

Why do you want to strip the comments out?

-- Peter Bushell

formatting link

Reply to
Peter Bushell

See

formatting link
Our C formatter can do both of these tasks trivially.

I'd guess from your interest in stripping comments that you might be interested in obfuscating the source. The same page will lead to a link to C obfuscating tools.

--
Ira D. Baxter, Ph.D., CTO   512-250-1018
Semantic Designs, Inc.      www.semdesigns.com
 Click to see the full signature
Reply to
Ira Baxter

Peter Bushell wrote: [...]

My question. I used to say that incorrect comments (stale or initially wrong) are much worse than no comment at all. Maybe he wants to strip them out and start over.

Reply to
Bryan Hackney

Amen. I find that more often than not when given some old code to fix/update I'm better off just deleting the comments so that I don't get misled.

Somebody ought to write a paper entitled "Comments Considered Harmful". Maybe somebody already has...

--
Grant Edwards                   grante             Yow!  But they went to MARS
                                  at               around 1953!!
 Click to see the full signature
Reply to
Grant Edwards

Even so, I don't see how deleting them *all* in a single sweep, before rewriting them from scratch is going to do you much good. Just cut out the old contents as you replace them with new ones, making sure you leave a fingerprint to distinguish rewritten comments from legacy ones if you don't do it strictly in linear order down the source...

Even a collection of mostly misguided comment may still contain the occasional pearl you'll need to understand the program good enough to write your own ones... Classifying them all as wrong without personally reading every last one of them (by letting a machine kill them away) is arguably just as silly as taking them all to be written gospel.

--
Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.
Reply to
Hans-Bernhard Broeker

Hi Bryan,

there are two reasons:

  1. the MISRA industry guidelines say that the production code should be free of any comment.
  2. My customer wants two versions of the code I'm writing for him: the commented and a "clean" one.

Enrico

Reply to
Enrico Migliore

I've never looked into MISRA, and probably never will, but this is very strange. Who came up with that and why?

My code is free of comments by the time the compiler gets it.

Reply to
Bryan Hackney

Agreed. I didn't mean to imply that deleting them all completely before starting was a good idea.

Mostly I deleting the comment and replace the _code_ with code that is readable. The only comments I find generally useful are a high-level description of what a function is supposed to be used for. Occasionally a comment describing what a particular obtuse block of code is intended to do can be helpful, but the low-level comments I often find trying to explain what's going on line-by-line are usually worse than useless.

--
Grant Edwards                   grante             Yow!  I guess it was all a
                                  at               DREAM... or an episode of
 Click to see the full signature
Reply to
Grant Edwards

[...]

// declare local variables int x, y; // set x equal to 1 x = 1; // set y equal to x times 3 y = x * 3; ...

:)

Reply to
Bryan Hackney

No kidding, I've seen code like that written be supposedly educated and professional induhviduals. Except it's often something like this:

// declare local variables int x, y; // set x equal to 1 x = 1; // set y equal to x times 3 y = x * (z/2 + 1);

Where they didn't want to use 3 anymore, and now there's a global varaible "z" that controls something, and the expression (z/2 + 1) probably isn't 3 anymore.

--
Grant Edwards                   grante             Yow!  Here I am in the
                                  at               POSTERIOR OLFACTORY LOBULE
 Click to see the full signature
Reply to
Grant Edwards

Hire an intern ;-)

Jamie

Reply to
Jamie

snip

Hello Enrico

I think you may have misunderstood the MISRA guidelines. I checked mine (dated April 1998) and on page 23 it refers to comments under Rules 7.3

it says: Rule 9 (required) Comments shall not be nested

Rule 10 (advisory) Sections of code should not be 'commented out'

Perhaps there is a newer version - please let me know because I can't think of any reason at all (and I mean ANY) to deliberately use two different source code's for the same project - which do you test ?

Michael Kellett

Reply to
mk

Well, no comments at all would certainly satisfy r10 and r9 ;)

Given the level of C competence of most of the MISRA committee (in one draft I saw plenty of the examples weren't even in legal C)... who knows what they *meant*?

MISRA have taken years to turn Les Hatton's excellent work on Safer C into a morass of mealy-mouthed 'guidelines'.

pete

--
pete@fenelon.com "there's no room for enigmas in built-up areas."
Reply to
Pete Fenelon

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.