www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - __BASE_FILE__

↑ ↓ ← "Matthew Wilson" <matthew stlsoft.org> writes:
Walter

Could we have a __BASE_FILE__ (or equivalent) in DMC/C++?

It corresponds to the name of the source file specific to the compiler.

Matthew
Oct 17 2003
→ Jan Knepper <jan smartsoft.us> writes:
I think there is already such as thing as __FILE__

const char *    __BASE_FILE__ = __FILE__;

Jan



Matthew Wilson wrote:
 Walter
 
 Could we have a __BASE_FILE__ (or equivalent) in DMC/C++?
 
 It corresponds to the name of the source file specific to the compiler.
 
 Matthew
 
 

-- ManiaC++ Jan Knepper
Oct 17 2003
"Walter" <walter digitalmars.com> writes:
"Matthew Wilson" <matthew stlsoft.org> wrote in message
news:bmoa2j$3f1$1 digitaldaemon.com...
 Walter

 Could we have a __BASE_FILE__ (or equivalent) in DMC/C++?

 It corresponds to the name of the source file specific to the compiler.

What's different between that and __FILE__?
Oct 17 2003
↑ ↓ "Matthew Wilson" <matthew stlsoft.org> writes:
__FILE__ gives the name of whatever source file it is used in

__BASE_FILE__ gives the name of the source file specified to the compiler

// header.h

const char hname[] = __FILE__;

const char sname[] = __BASE_FILE__;

// source1.c

#include "header.h"

printf("%s\n", hname);   // Prints "header.h"
printf("%s\n", sname);  // Prints "source1.c"

// source2.cpp

#include "header.h"

cout << hname << endl;  // Prints "header.h"
cout << sname << endl;  // Prints "source2.cpp"


GCC has this, and some others may do. I'm using this in a section in the
book and, of course, it'd be good to say that DMC++ also supports. IIRC,
there is talk of adding this to the C & C++ standards, though I forget the
source for that rememberance.

I know you don't like adding things to the compiler, but this must be simple
to do, is done elsewhere, would be very useful, and it'd get DMC++ more
mentions here and there. ;)




"Walter" <walter digitalmars.com> wrote in message
news:bmp7ev$1ami$1 digitaldaemon.com...
 "Matthew Wilson" <matthew stlsoft.org> wrote in message
 news:bmoa2j$3f1$1 digitaldaemon.com...
 Walter

 Could we have a __BASE_FILE__ (or equivalent) in DMC/C++?

 It corresponds to the name of the source file specific to the compiler.

What's different between that and __FILE__?

Oct 17 2003
↑ ↓ "Walter" <walter digitalmars.com> writes:
Thanks for explaining it. I did a google search on it, and it appears to be
gcc only. There were 949 hits on it, vs 119,000 hits for __FILE__. I was
unable to find any rationale for __BASE_FILE__. It isn't hard to implement,
but the trouble with it is once it is there, it is there forever. Breaking
existing code is bad for business <g>.  There are several DMC features that
I wish I could remove now, but they are needed for unknown quantities of
legacy code. More features mean more bloat, more documentation, more
testing, and more bugs. (Reminds me of when I worked for Boeing, we were
constantly reminded that every pound of weight was a cost that kept on
costing money, in every airplane in every moment it flew.) I need a strong
rationale for it. If you can find the ANSI C proposal for it, that might do.

-Walter

"Matthew Wilson" <matthew stlsoft.org> wrote in message
news:bmphi1$1ou0$1 digitaldaemon.com...
 __FILE__ gives the name of whatever source file it is used in

 __BASE_FILE__ gives the name of the source file specified to the compiler

 // header.h

 const char hname[] = __FILE__;

 const char sname[] = __BASE_FILE__;

 // source1.c

 #include "header.h"

 printf("%s\n", hname);   // Prints "header.h"
 printf("%s\n", sname);  // Prints "source1.c"

 // source2.cpp

 #include "header.h"

 cout << hname << endl;  // Prints "header.h"
 cout << sname << endl;  // Prints "source2.cpp"


 GCC has this, and some others may do. I'm using this in a section in the
 book and, of course, it'd be good to say that DMC++ also supports. IIRC,
 there is talk of adding this to the C & C++ standards, though I forget the
 source for that rememberance.

 I know you don't like adding things to the compiler, but this must be

 to do, is done elsewhere, would be very useful, and it'd get DMC++ more
 mentions here and there. ;)




 "Walter" <walter digitalmars.com> wrote in message
 news:bmp7ev$1ami$1 digitaldaemon.com...
 "Matthew Wilson" <matthew stlsoft.org> wrote in message
 news:bmoa2j$3f1$1 digitaldaemon.com...
 Walter

 Could we have a __BASE_FILE__ (or equivalent) in DMC/C++?

 It corresponds to the name of the source file specific to the



 What's different between that and __FILE__?


Oct 17 2003
↑ ↓ "Matthew Wilson" <matthew stlsoft.org> writes:
A simple example (from the book):


// CUTrace.h

extern void CUTraceHelper(char const *file, char const *msg, va_list args);



static void CUTrace(char const *message, ...)

{

  va_list args;



  va_start(fmt, args);



  CUTraceHelper(__BASE_FILE__, message, args);



  va_end(args);

}





I understand your reticence, and am not surprised by your refusal. Still, it
would be nice ...


"Walter" <walter digitalmars.com> wrote in message
news:bmpom6$23ie$1 digitaldaemon.com...
 Thanks for explaining it. I did a google search on it, and it appears to

 gcc only. There were 949 hits on it, vs 119,000 hits for __FILE__. I was
 unable to find any rationale for __BASE_FILE__. It isn't hard to

 but the trouble with it is once it is there, it is there forever. Breaking
 existing code is bad for business <g>.  There are several DMC features

 I wish I could remove now, but they are needed for unknown quantities of
 legacy code. More features mean more bloat, more documentation, more
 testing, and more bugs. (Reminds me of when I worked for Boeing, we were
 constantly reminded that every pound of weight was a cost that kept on
 costing money, in every airplane in every moment it flew.) I need a strong
 rationale for it. If you can find the ANSI C proposal for it, that might

 -Walter

 "Matthew Wilson" <matthew stlsoft.org> wrote in message
 news:bmphi1$1ou0$1 digitaldaemon.com...
 __FILE__ gives the name of whatever source file it is used in

 __BASE_FILE__ gives the name of the source file specified to the


 // header.h

 const char hname[] = __FILE__;

 const char sname[] = __BASE_FILE__;

 // source1.c

 #include "header.h"

 printf("%s\n", hname);   // Prints "header.h"
 printf("%s\n", sname);  // Prints "source1.c"

 // source2.cpp

 #include "header.h"

 cout << hname << endl;  // Prints "header.h"
 cout << sname << endl;  // Prints "source2.cpp"


 GCC has this, and some others may do. I'm using this in a section in the
 book and, of course, it'd be good to say that DMC++ also supports. IIRC,
 there is talk of adding this to the C & C++ standards, though I forget


 source for that rememberance.

 I know you don't like adding things to the compiler, but this must be

 to do, is done elsewhere, would be very useful, and it'd get DMC++ more
 mentions here and there. ;)




 "Walter" <walter digitalmars.com> wrote in message
 news:bmp7ev$1ami$1 digitaldaemon.com...
 "Matthew Wilson" <matthew stlsoft.org> wrote in message
 news:bmoa2j$3f1$1 digitaldaemon.com...
 Walter

 Could we have a __BASE_FILE__ (or equivalent) in DMC/C++?

 It corresponds to the name of the source file specific to the



 What's different between that and __FILE__?



Oct 17 2003
↑ ↓ → "Walter" <walter digitalmars.com> writes:
"Matthew Wilson" <matthew stlsoft.org> wrote in message
news:bmq1oc$2f2g$2 digitaldaemon.com...
 A simple example (from the book):
 // CUTrace.h
 extern void CUTraceHelper(char const *file, char const *msg, va_list

 static void CUTrace(char const *message, ...)
 {
   va_list args;
   va_start(fmt, args);
   CUTraceHelper(__BASE_FILE__, message, args);
   va_end(args);
 }
 I understand your reticence, and am not surprised by your refusal. Still,

 would be nice ...

Thanks. I hate saying no, but I have to be ruthless in picking what to spend time on. I've got such a long list of things that have to be done regardless. Each hill I climb reveals a higher one behind it <g>.
Oct 17 2003
→ "Marc Côté" <mark.cote sympatico.ca> writes:
"Matthew Wilson" <matthew stlsoft.org> wrote in message
news:bmoa2j$3f1$1 digitaldaemon.com...
 Walter
 Could we have a __BASE_FILE__ (or equivalent) in DMC/C++?

Is it what you are talking about ? From the GNU doc: http://www.fokus.gmd.de/gnu/docs/gcc/cpp_13.html#SEC14 Standard Predefined Macros The standard predefined macros are available with the same meanings regardless of the machine or operating system on which you are using GNU C. Their names all start and end with double underscores. Those preceding __GNUC__ in this table are standardized by ANSI C; the rest are GNU C extensions. __FILE__ This macro expands to the name of the current input file, in the form of a C string constant. The precise name returned is the one that was specified in `#include' or as the input file name argument. __BASE_FILE__ This macro expands to the name of the main input file, in the form of a C string constant. This is the source file that was specified as an argument when the C compiler was invoked. __INCLUDE_LEVEL__ This macro expands to a decimal integer constant that represents the depth of nesting in include files. The value of this macro is incremented on every `#include' directive and decremented at every end of file. For input files specified by command line arguments, the nesting level is zero.
Oct 17 2003