Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: LOC

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.


Jeremy

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://185314]
help
Chatterbox?
[marto]: good morning all

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2018-02-20 10:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (268 votes). Check out past polls.

    Notices?