macros question

A

Andrew Arro

so, we have built-in __FILE__ and __LINE__

how could we define
__FILELINE__ macros so it would be smth like, for example, "file.c:11"

i've tried
#define __FILELINE__ __FILE__ ## ":" ## __LINE__
and
#define __FILELINE__ __FILE__ ## ":" ## #__LINE__

and a bunch of different combinations but none work for me :(
 
A

Alexander Bartolich

begin followup to Andrew Arro:
how could we define
__FILELINE__ macros so it would be smth like, for example, "file.c:11"

$ nl -ba f.c
1 #include <stdio.h>
2
3 #define QUOTE_STR(s) #s
4 #define QUOTE_NUM(n) QUOTE_STR(n)
5 #define __FILELINE__ __FILE__ ":" QUOTE_NUM(__LINE__)
6
7 int main()
8 {
9 puts(__FILELINE__);
10 return 0;
11 }
$> gcc -Wall f.c && ./a.out
f.c:9
i've tried
#define __FILELINE__ __FILE__ ## ":" ## __LINE__
and
#define __FILELINE__ __FILE__ ## ":" ## #__LINE__

Nonsense.
 
R

Régis Troadec

Andrew Arro said:
so, we have built-in __FILE__ and __LINE__

how could we define
__FILELINE__ macros so it would be smth like, for example, "file.c:11"

i've tried
#define __FILELINE__ __FILE__ ## ":" ## __LINE__
and
#define __FILELINE__ __FILE__ ## ":" ## #__LINE__

and a bunch of different combinations but none work for me :(

Hi,

You can take a look at the 11.7 FAQ to stringize macros.

I suggest you this example :

/********/
/* exple.c */
/********/
#include <stdio.h>

/* stringizing stuff */
#define GEN_STRING(x) #x
#define STRINGIZE(x) GEN_STRING(x)

/* stringize expanded built-in macros __FILE__ and __LINE __*/
#define FILELINE STRINGIZE(__FILE__ : __LINE__)

int main(void)
{
printf(FILELINE "\n");
return 0;
}

/* That's all folks */

Notes :
1) I would avoid beginning my identifiers with __, since many predefined
macros and others use it.
2) assert() already displays informations using __FILE__ and __LINE__

HTH
Regis
 
M

Mike Wahler

Please STOP posting attachments to this newsgroup.
If you have code to share, paste it into the
body of your message (text only).

-Mike
 
B

Ben Pfaff

Mike Wahler said:
Please STOP posting attachments to this newsgroup.

He didn't post any attachments. His article was plain text only.
However, I see that you're posting using a broken newsreader.
Fix that and you'll have no problems.
 
J

Jack Klein

Please STOP posting attachments to this newsgroup.
If you have code to share, paste it into the
body of your message (text only).

-Mike

What attachment? The post you are complaining about was plain text.
 
M

Martin Ambuhl

Mike said:
Please STOP posting attachments to this newsgroup.
If you have code to share, paste it into the
body of your message (text only).

Actually, he did not post an attachment. What he *did* do was to begin
his post withwhich your Microsoft Outlook Express 6.00.2800.1106 decided to treat as
signalling an attachment.

Alexander, if you want your messages to be read, do not start them with
the word "begin."
 
R

Richard Heathfield

Mike said:
Please STOP posting attachments to this newsgroup.

Mike, there are lots of newsreaders out there that work just fine. So why
are you using a broken one? :)
 
C

Christopher Benson-Manica

Martin Ambuhl said:
Alexander, if you want your messages to be read, do not start them with
the word "begin."

ITYM "if you want your messages to be read by Mike", as most of us had
no difficulty :)
 
K

Keith Thompson

Christopher Benson-Manica said:
ITYM "if you want your messages to be read by Mike", as most of us had
no difficulty :)

There are two problems here.

1. Some newsreader(s) incorrectly interpret a line in the body of a
message starting with "begin " as the beginning of an attachment.
(If there's a way to disable this misfeature, someone could save us
all a lot of trouble by letting us know how to do it.) I'm guessing
that a bug report has already been submitted; it would probably be a
good idea for anyone who uses the newsreader(s) in question to
encourage the vendor to fix it.

2. Alexander deliberately antagonizes users of the broken
newsreader(s) in question by posting articles containing lines
starting with "begin ". (I don't believe it's accidental; the double
space after the "begin" is too specific.) I humbly submit that
Alexander has made his point, and that it's time for him to knock it
off. Antagonizing the authors of broken newsreaders is just fine.
Antagonizing the users of broken newsreaders, who may or may not have
a real choice in the matter and who may or may not have any influence
over the vendor, is questionable, but I won't argue that he shouldn't
do it. Indirectly antagonizing the entire readership of comp.lang.c
(because Alexander should know by now what the response is going to
be) may have seemed like a good idea at the time, but it's no longer
serving any useful purpose.
 
R

Richard Heathfield

Keith said:
Indirectly antagonizing the entire readership of comp.lang.c
(because Alexander should know by now what the response is going to
be) may have seemed like a good idea at the time, but it's no longer
serving any useful purpose.

Not quite the /entire/ readership. :)
 
C

CBFalconer

Richard said:
Ditto. OutLook is OutDated, and should be OutStamped.

The problem with the "solution" is that lusers of the inferior
buggy software will never realize what is going on. Now if that
initial "begin " could be replaced by something that would flash
"Your @#$% reader is bug-infested" in large letters at about 2
flashes per second on ONLY the aforesaid bug-infested software, we
would have something worth while.
 
B

Ben Pfaff

CBFalconer said:
The problem with the "solution" is that lusers of the inferior
buggy software will never realize what is going on. Now if that
initial "begin " could be replaced by something that would flash
"Your @#$% reader is bug-infested" in large letters at about 2
flashes per second on ONLY the aforesaid bug-infested software, we
would have something worth while.

Here's an approximation:
 
J

Joona I Palaste

Here's an approximation:
begin 644 foo
A66]U<B!`(R0E(')E861E<B!I<R!B=6<M:6YF97-T960*
`
end

For us who use non-broken newsreaders (such as tin), and don't want to
go through the hassle of Base64-converting it by hand, what does it do?
 
B

Ben Pfaff

Joona I Palaste said:
Here's an approximation:
begin 644 foo
A66]U<B!`(R0E(')E861E<B!I<R!B=6<M:6YF97-T960*
`
end

For us who use non-broken newsreaders (such as tin), and don't want to
go through the hassle of Base64-converting it by hand, what does it do?

It decodes to "Your @#$% reader is bug-infested".
 
J

Joona I Palaste

Ben Pfaff said:
Joona I Palaste said:
Ben Pfaff said:
The problem with the "solution" is that lusers of the inferior
buggy software will never realize what is going on. Now if that
initial "begin " could be replaced by something that would flash
"Your @#$% reader is bug-infested" in large letters at about 2
flashes per second on ONLY the aforesaid bug-infested software, we
would have something worth while.
Here's an approximation:
begin 644 foo
A66]U<B!`(R0E(')E861E<B!I<R!B=6<M:6YF97-T960*
`
end

For us who use non-broken newsreaders (such as tin), and don't want to
go through the hassle of Base64-converting it by hand, what does it do?
It decodes to "Your @#$% reader is bug-infested".

With or without the large letters at about 2 flashes per second? =)
 
J

Joe Wright

Joona said:
Ben Pfaff said:
CBFalconer said:
The problem with the "solution" is that lusers of the inferior
buggy software will never realize what is going on. Now if that
initial "begin " could be replaced by something that would flash
"Your @#$% reader is bug-infested" in large letters at about 2
flashes per second on ONLY the aforesaid bug-infested software, we
would have something worth while.

Here's an approximation:

begin 644 foo
A66]U<B!`(R0E(')E861E<B!I<R!B=6<M:6YF97-T960*
`
end


For us who use non-broken newsreaders (such as tin), and don't want to
go through the hassle of Base64-converting it by hand, what does it do?
It is uuencoded and represents ascii..

Your @#$% reader is bug-infested
 
D

Dan Pop

In said:
Here's an approximation:
begin 644 foo
A66]U<B!`(R0E(')E861E<B!I<R!B=6<M:6YF97-T960*
`
end

For us who use non-broken newsreaders (such as tin), and don't want to
go through the hassle of Base64-converting it by hand, what does it do?

Non-broken newsreaders should be able to handle uuencoded content just
fine, since this is the de facto standard binary encoding method of the
Usenet. Consider your newsreader broken if it cannot, at least, create
a file named foo and containing the decoded data, upon your explicit
request.

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,817
Members
47,362
Latest member
ChandaWagn

Latest Threads

Top