From: Aniruddha Bhattacharyya <aniruddha.aot@gmail.com>
To: Michal Nazarewicz <mina86@mina86.com>
Cc: ratheesh kannoth <ratheesh.ksz@gmail.com>,
Zhongye Jia <jia.zhongye@gmail.com>,
linux-c-programming@vger.kernel.org
Subject: Re: macro to print filename
Date: Thu, 2 Jun 2011 00:54:59 +0530 [thread overview]
Message-ID: <BANLkTimHdt6psdjPjKAPskBxaycF=-BECw@mail.gmail.com> (raw)
In-Reply-To: <op.vwevk4xc3l0zgt@mnazarewicz-glaptop>
From what I understood, Ratheesh wanted a compile time solution.
My workaround will be to go for a Makefile based compilation.
1) "gcc -E yourfile.c" will preprocess only. so __FILE__ will be expanded .
output file will be yourfile.c (with macro expanded)
2) then run your custom tool/bash script to trim the filepath to filename.
use awk tool maybe.
3) Do the final compile using Gcc
On Thu, Jun 2, 2011 at 12:41 AM, Michal Nazarewicz <mina86@mina86.com> wrote:
>
> On Wed, 01 Jun 2011 20:08:50 +0200, Zhongye Jia <jia.zhongye@gmail.com> wrote:
>>
>> #include <stdio.h>
>>
>> int main()
>> {
>> char filename[] = __FILE__, *basename;
>> basename = filename + sizeof(filename) - 2;
>> while( basename+1 != filename && *basename != '/' ) {
>> basename--;
>> }
>> basename++;
>
> And you are not using strchr() why? I know OP said about not using
> string libraries but I don't think he meant that he's fine with
> reimplementing the wheel.
>
>> printf("%s\n%s\n", filename, basename);
>> return 0;
>> }
>
> --
> Best regards, _ _
> .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
> ..o | Computer Science, Michal "mina86" Nazarewicz (o o)
> ooo +-----<email/xmpp: mnazarewicz@google.com>-----ooO--(_)--Ooo--
> --
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2011-06-01 19:24 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-01 16:07 macro to print filename ratheesh kannoth
2011-06-01 17:38 ` Michal Nazarewicz
2011-06-01 18:45 ` Zhongye Jia
2011-06-01 19:08 ` Michal Nazarewicz
2011-06-02 13:39 ` Zhongye Jia
2011-06-02 18:11 ` ratheesh kannoth
2011-06-02 19:11 ` Michal Nazarewicz
2011-06-01 18:08 ` Zhongye Jia
2011-06-01 19:11 ` Michal Nazarewicz
2011-06-01 19:24 ` Aniruddha Bhattacharyya [this message]
2011-06-01 19:27 ` Michal Nazarewicz
2011-06-02 2:10 ` Libin Yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='BANLkTimHdt6psdjPjKAPskBxaycF=-BECw@mail.gmail.com' \
--to=aniruddha.aot@gmail.com \
--cc=jia.zhongye@gmail.com \
--cc=linux-c-programming@vger.kernel.org \
--cc=mina86@mina86.com \
--cc=ratheesh.ksz@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).