Trivial but annoying

Hi,

I came across this silly little problem in MSVC6 and it annoyed me enough
to want to post it here to see if anyone else could solve it.

The MSVC compiler supports the ‘message’ pragma for outputting messages to
the build window during compilation. E.g (from MSDN library) :-

#pragma message( "Compiling " FILE )
#pragma message( "Last modified on " TIMESTAMP )

I wanted to use the LINE macro to output the file name (using FILE)
and the line number within the file. I.e. something like this :-

#pragma message( FILE “(” LINE “) : Warning - something nasty
here!”)

Unfortunately, the LINE macro is not a quoted string (like FILE)
but just a plain integer and I spent far too long trying to persuade it to
behave as a string but ended up failing miserably.

Any ideas folks?
Simon.


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Hi,
We use the following macros to do what I think you want:

#define STR2(x) #x
#define STR1(x) STR2(x)
#define LOCMSG FILE "(“STR1(LINE)”) : Message: "
#define LOCWRN FILE "(“STR1(LINE)”) : Warning: "

therefore:

#pragma message(LOCMSG"Information message")
#pragma message(LOCWRN"Warning message")

generates the following compiler output:

D:\projects\Testing\Testfile.cpp(15) : Message: Information message
D:\projects\Testing\Testfile.cpp(16) : Warning: Warning message

a message labelled with ‘Warning’ generates a complier warning.

The above macros have been used with Visual C++ 1.5 -> 6.0 to provide
information whilst compiling which when double clicked on takes you to the
line with the message on.

HTH

Alun Carp
Driver Development Team Leader
Data Encryption Systems Limited

-----Original Message-----
From: Simon Bonner [mailto:xxxxx@normanuk.com]
Sent: 11 January 2001 16:38
To: NT Developers Interest List
Subject: [ntdev] Trivial but annoying

Hi,

I came across this silly little problem in MSVC6 and it annoyed me enough
to want to post it here to see if anyone else could solve it.

The MSVC compiler supports the ‘message’ pragma for outputting messages to
the build window during compilation. E.g (from MSDN library) :-

#pragma message( "Compiling " FILE )
#pragma message( "Last modified on " TIMESTAMP )

I wanted to use the LINE macro to output the file name (using FILE)
and the line number within the file. I.e. something like this :-

#pragma message( FILE “(” LINE “) : Warning - something nasty
here!”)

Unfortunately, the LINE macro is not a quoted string (like FILE)
but just a plain integer and I spent far too long trying to persuade it to
behave as a string but ended up failing miserably.

Any ideas folks?
Simon.


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Indeed.

See “HOWTO: Use #pragma to Generate User-Defined Warning Messages”
For more detail and explanation.

Regards,

Paul Bunn, UltraBac.com, 425-644-6000
Microsoft MVP - WindowsNT/2000
http://www.ultrabac.com

-----Original Message-----
From: Alun Carp [mailto:xxxxx@des.co.uk]
Sent: Thursday, January 11, 2001 8:50 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Trivial but annoying

Hi,
We use the following macros to do what I think you want:

#define STR2(x) #x
#define STR1(x) STR2(x)
#define LOCMSG FILE "(“STR1(LINE)”) : Message: "
#define LOCWRN FILE "(“STR1(LINE)”) : Warning: "

therefore:

#pragma message(LOCMSG"Information message")
#pragma message(LOCWRN"Warning message")

generates the following compiler output:

D:\projects\Testing\Testfile.cpp(15) : Message: Information message
D:\projects\Testing\Testfile.cpp(16) : Warning: Warning message

a message labelled with ‘Warning’ generates a complier warning.

The above macros have been used with Visual C++ 1.5 -> 6.0 to provide
information whilst compiling which when double clicked on takes you to the
line with the message on.

HTH

Alun Carp
Driver Development Team Leader
Data Encryption Systems Limited

-----Original Message-----
From: Simon Bonner [mailto:xxxxx@normanuk.com]
Sent: 11 January 2001 16:38
To: NT Developers Interest List
Subject: [ntdev] Trivial but annoying

Hi,

I came across this silly little problem in MSVC6 and it annoyed me enough
to want to post it here to see if anyone else could solve it.

The MSVC compiler supports the ‘message’ pragma for outputting messages to
the build window during compilation. E.g (from MSDN library) :-

#pragma message( "Compiling " FILE )
#pragma message( "Last modified on " TIMESTAMP )

I wanted to use the LINE macro to output the file name (using FILE)
and the line number within the file. I.e. something like this :-

#pragma message( FILE “(” LINE “) : Warning - something nasty
here!”)

Unfortunately, the LINE macro is not a quoted string (like FILE)
but just a plain integer and I spent far too long trying to persuade it to
behave as a string but ended up failing miserably.


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Hi Alun,

Yes that’s EXACTLY what I was trying to do. Thank you!

I hadn’t tried going through two levels of macro though (STR1 and STR2).

Regards,
Simon.

Alun Carp
To: “NT Developers Interest List”
Sent by: cc:
xxxxx@lis Subject: [ntdev] RE: Trivial but annoying
ts.osr.com

11/01/01 16:49
Please respond to
“NT Developers
Interest List”

Hi,
We use the following macros to do what I think you want:

#define STR2 (x) #x
#define STR1 (x) STR2 (x)
#define LOCMSG FILE"(" STR1 ( LINE )“) : Message: “
#define LOCWRN FILE”(” STR1 ( LINE )“) : Warning: “

therefore:

#pragma message( LOCMSG"Information message”)
#pragma message( LOCWRN"Warning message”)

generates the following compiler output:

D:\projects\Testing\Testfile.cpp(15) : Message: Information message
D:\projects\Testing\Testfile.cpp(16) : Warning: Warning message

a message labelled with ‘Warning’ generates a complier warning.

The above macros have been used with Visual C++ 1.5 -> 6.0 to provide
information whilst compiling which when double clicked on takes you to the
line with the message on.

HTH

Alun Carp
Driver Development Team Leader
Data Encryption Systems Limited

-----Original Message-----
From: Simon Bonner [mailto:xxxxx@normanuk.com]
Sent: 11 January 2001 16:38
To: NT Developers Interest List
Subject: [ntdev] Trivial but annoying

Hi,

I came across this silly little problem in MSVC6 and it annoyed me enough
to want to post it here to see if anyone else could solve it.

The MSVC compiler supports the ‘message’ pragma for outputting messages to
the build window during compilation. E.g (from MSDN library) :-

#pragma message( “Compiling " FILE )
#pragma message( “Last modified on " TIMESTAMP )

I wanted to use the LINE macro to output the file name (using FILE )
and the line number within the file. I.e. something like this :-

#pragma message( FILE”(” LINE") : Warning - something nasty
here!")

Unfortunately, the LINE macro is not a quoted string (like FILE )
but just a plain integer and I spent far too long trying to persuade it to
behave as a string but ended up failing miserably.

Any ideas folks?
Simon.


You are currently subscribed to ntdev as: xxxxx@normanuk.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com