Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask


by enoch (Chaplain)
on Jul 25, 2002 at 20:10 UTC ( #185314=note: print w/replies, xml ) Need Help??

in reply to Counting lines of C code

As other people have stated wc -l is the easy way to go. But, if you want "lines" of code as in actual code statements, well, that gets a little more rough.

Parsing out comments in C/C++ is not trivial. Page 293 of Mastering Regular Expressions, 1st Edition gives a regex that will remove multiline C comments ( /* */ style), but like I said, it is non-trivial.

Furthermore, statements, themselves, could span multiple lines; thus, making a line count of non-comment lines be not indicative of how many statements of code are in a file.
if( foo ) i = 1; // just one statement if( foo ) i = 1; // still just one statement if( foo ) { i = 1; // still just one } if ( foo ) { i = 1; // 1 statement }

So, I doubt it would be worth the effort to try and define statements of C/C++ code and count them. I would stick to wc -l.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://185314]
[Discipulus]: good morning community!
[Corion]: Good morning Discipulus!

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2018-06-19 07:08 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (111 votes). Check out past polls.