tags:

views:

140

answers:

3

Hi, I wanted to know at which line number are the declarations in a given C function. Also which lines have if/while/for loops or which lines span multiple lines (ie they donot end on same line).

+2  A: 

I think we need to know why you want the line number in order to help you.

Variously:

1) You can use __LINE__ in the code to get the current line number. 2) Most editors can show the line numbers next to the code.

If you want to script breakpoints, I'm not sure if that's possible - I'd suggest setting break-points on filename and function, and then splitting up the code till that's sufficient. Alternatively investigate other ways of getting the testing done - e.g. splitting up the code so unit tests can check it.

Douglas Leeder
+1  A: 

Maybe I did not understand your question, but you can use ctags (or one of its variants) to get a list of declarations and their line numbers.

For example exuberant ctags is capable of generating tags (line numbers) for all types of C/C++ language tags, including all of the following:

  • class names
  • macro definitions
  • enumeration names
  • enumerators
  • function definitions
  • function prototypes/declarations
  • class, interface, struct, and union data members
  • structure names
  • typedefs
  • union names
  • variables (definitions and external declarations)
uvts_cvs
yes, i tried evaluating ctags, but it was showing me global variablesand not local variables. will investigate more
A: 

If you can, use the diff tool. It provides line numbers as part of the output. Your tool could then parse that output, looking for declarations or primary code.

Bill Perkins