Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2017-12-14 03:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (384 votes). Check out past polls.

    Notices?