There are other uses besides logging, or at least the kind of logging you're thinking of.
For example, let's say you have a large complex server with large complex datastructures with long lifetimes, and a high server availability requirement. Let's say you experience a problem in production, that you have not been able to reproduce in testing. Or, that you can reproduce only with such a low frequency that slowing it down significantly is unacceptable. So you tag a structure with where it is created and/or modified. You may even do this preemptively, so that you CAN log and analyze these post-failure. There are a few other circumstances, even less common. And don't assume that performance is not important for logging. The more efficient logging is, the more you can afford to use it, and the better you can maintain your program while in production. Finally, the usual C/C++ use of __FILE__ and __LINE__ is in a macro that calls a function that takes them as arguments. You can play tricks with this (and #undef) to allow you to not have to rewrite your code when the base function was not designed to take them as arguments, but to redirect the calls to a debug version. Nothing here requiring a preprocessor, of course, just macros and the __FILE__ and __LINE__ directives. On Aug 3, 6:21 am, Kostya Vasilyev <kmans...@gmail.com> wrote: > The main reason to need these is logging / debugging, so runtime > overhead is acceptable. Or am I missing something? > > On the other hand, __FILE__ and __LINE__ are only valid where they are > used - there is no way to get the caller's file and line info, so it has > to be passed to whatever functions you want to use them in. > > And that is certainly a maintenance issue - what if you decide to log > caller file and line in a function that was not designed for it from the > start? > > It also would be interesting to know why exactly the OP thought he > needed the preprocessor. Who knows, maybe he wanted to produce separate > versions of his application for different screen sizes / densities? > > -- Kostya > > 03.08.2010 17:10, DanH пишет: > > > > > > > Right. The compiler knows what the line number is (at least if > > there's no preprocessor in the way). It can return that from a pseudo- > > function. Same for class, method, etc. > > > On Aug 2, 10:03 pm, Bob Kerns<r...@acm.org> wrote: > > >> Note that you don't need a preprocessor to do this! Just a bit of > >> language support. > > >> On Aug 2, 8:01 pm, Bob Kerns<r...@acm.org> wrote: > > >>> Yes, I've seen a few cases like this. There are ways to cache the > >>> runtime call, which can be a bit expensive, but they rely a bit much > >>> on convention and are a bit more verbose than you'd like. > > >>> On Aug 2, 7:02 pm, DanH<danhi...@ieee.org> wrote: > > >>>> Lots of times it would be nice for logging. Sometimes you'd like to > >>>> store an "I was here" indicator in a structure when you modify it. > >>>> Yes, there are alternatives, but not as nice. > > -- > Kostya Vasilev -- WiFi Manager + pretty widget --http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en