Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #16498 > unrolled thread

trigraphs, yecch

Started bycri@tiac.net (Richard Harter)
First post2012-01-31 15:55 +0000
Last post2012-02-01 16:52 +0000
Articles 20 on this page of 48 — 20 participants

Back to article view | Back to comp.lang.c


Contents

  trigraphs, yecch cri@tiac.net (Richard Harter) - 2012-01-31 15:55 +0000
    Re: trigraphs, yecch pete <pfiland@mindspring.com> - 2012-01-31 11:05 -0500
      Re: trigraphs, yecch Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-31 16:47 +0000
        Re: trigraphs, yecch cri@tiac.net (Richard Harter) - 2012-01-31 17:21 +0000
          Re: trigraphs, yecch James Kuyper <jameskuyper@verizon.net> - 2012-01-31 12:26 -0500
          Re: trigraphs, yecch Robert Wessel <robertwessel2@yahoo.com> - 2012-01-31 11:40 -0600
            Re: trigraphs, yecch Keith Thompson <kst-u@mib.org> - 2012-01-31 15:22 -0800
              Re: trigraphs, yecch "BartC" <bc@freeuk.com> - 2012-02-01 01:09 +0000
                Re: trigraphs, yecch James Kuyper <jameskuyper@verizon.net> - 2012-01-31 22:21 -0500
                Re: trigraphs, yecch Keith Thompson <kst-u@mib.org> - 2012-01-31 21:25 -0800
              Re: trigraphs, yecch "Charles Richmond" <netnews@aquaporin4.com> - 2012-01-31 23:40 -0600
                Re: trigraphs, yecch Keith Thompson <kst-u@mib.org> - 2012-01-31 22:19 -0800
                  Re: trigraphs, yecch James Kuyper <jameskuyper@verizon.net> - 2012-02-01 08:27 -0500
          Re: trigraphs, yecch Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-31 17:47 +0000
          Re: trigraphs, yecch ImpalerCore <jadill33@gmail.com> - 2012-01-31 09:41 -0800
          Re: trigraphs, yecch pete <pfiland@mindspring.com> - 2012-01-31 13:17 -0500
    Re: trigraphs, yecch blp@cs.stanford.edu (Ben Pfaff) - 2012-01-31 09:56 -0800
    Re: trigraphs, yecch Peter Nilsson <airia@acay.com.au> - 2012-01-31 13:55 -0800
      Re: trigraphs, yecch Harald van Dijk <haraldvdijk@gmail.com> - 2012-01-31 14:02 -0800
        Re: trigraphs, yecch blp@cs.stanford.edu (Ben Pfaff) - 2012-01-31 14:06 -0800
          Re: trigraphs, yecch Harald van Dijk <haraldvdijk@gmail.com> - 2012-01-31 15:13 -0800
          Re: trigraphs, yecch "Charles Richmond" <netnews@aquaporin4.com> - 2012-01-31 23:44 -0600
            Re: trigraphs, yecch Keith Thompson <kst-u@mib.org> - 2012-01-31 22:20 -0800
              Re: trigraphs, yecch James Harris <james.harris.1@googlemail.com> - 2012-01-31 22:56 -0800
                Re: trigraphs, yecch Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-02-01 12:15 +0000
    Re: trigraphs, yecch Keith Thompson <kst-u@mib.org> - 2012-01-31 15:27 -0800
      Re: trigraphs, yecch Patrick Scheible <kkt@zipcon.net> - 2012-01-31 17:01 -0800
        Re: trigraphs, yecch Keith Thompson <kst-u@mib.org> - 2012-01-31 19:50 -0800
          Re: trigraphs, yecch Patrick Scheible <kkt@zipcon.net> - 2012-02-01 10:31 -0800
        Re: trigraphs, yecch James Kuyper <jameskuyper@verizon.net> - 2012-01-31 23:17 -0500
          Re: trigraphs, yecch "Joachim Schmitz" <nospam.jojo@schmitz-digital.de> - 2012-02-01 10:39 +0100
          Re: trigraphs, yecch Kaz Kylheku <kaz@kylheku.com> - 2012-02-01 17:20 +0000
          Re: trigraphs, yecch Patrick Scheible <kkt@zipcon.net> - 2012-02-01 11:11 -0800
        Re: trigraphs, yecch "Charles Richmond" <netnews@aquaporin4.com> - 2012-01-31 23:50 -0600
          Re: trigraphs, yecch ralph <nt_consulting64@yahoo.net> - 2012-02-01 11:56 -0600
          Re: trigraphs, yecch Patrick Scheible <kkt@zipcon.net> - 2012-02-01 11:12 -0800
          Re: trigraphs, yecch Stephen Sprunk <stephen@sprunk.org> - 2012-02-01 13:29 -0600
            Re: trigraphs, yecch blp@cs.stanford.edu (Ben Pfaff) - 2012-02-01 11:35 -0800
              Re: trigraphs, yecch Kaz Kylheku <kaz@kylheku.com> - 2012-02-01 19:59 +0000
                Re: trigraphs, yecch blp@cs.stanford.edu (Ben Pfaff) - 2012-02-01 12:41 -0800
                  Re: trigraphs, yecch Kaz Kylheku <kaz@kylheku.com> - 2012-02-01 22:55 +0000
              Re: trigraphs, yecch Stephen Sprunk <stephen@sprunk.org> - 2012-02-01 14:44 -0600
                Re: trigraphs, yecch Kaz Kylheku <kaz@kylheku.com> - 2012-02-01 22:55 +0000
          Re: trigraphs, yecch "christian.bau" <christian.bau@cbau.wanadoo.co.uk> - 2012-02-02 14:19 -0800
            Re: trigraphs, yecch Patrick Scheible <kkt@zipcon.net> - 2012-02-06 20:40 -0800
              Re: trigraphs, yecch "Joachim Schmitz" <nospam.jojo@schmitz-digital.de> - 2012-02-07 11:40 +0100
        Re: trigraphs, yecch jgk@panix.com (Joe keane) - 2012-02-02 14:15 +0000
    Re: trigraphs, yecch cri@tiac.net (Richard Harter) - 2012-02-01 16:52 +0000

Page 1 of 3  [1] 2 3  Next page →


#16498 — trigraphs, yecch

Fromcri@tiac.net (Richard Harter)
Date2012-01-31 15:55 +0000
Subjecttrigraphs, yecch
Message-ID<4f2808f4.648026530@text.giganews.com>
The other day I wanted to put three successive question marks in a
string.  Frex, "(???).%s.%s".  My trusty antique gcc compiler
converted the last two '?'s into a ']' along with a warning that it
was doing a trigraph conversion.

Now, me, I know from nothing about trigraphs - never used them, hope
never to use them - so I was caught by surprise.  My elderly copy of
K&R described them but I didn't see anything about getting around
them.

So.  How is one supposed to get three successive question marks into a
string?
  

[toc] | [next] | [standalone]


#16499

Frompete <pfiland@mindspring.com>
Date2012-01-31 11:05 -0500
Message-ID<4F28113A.72C5@mindspring.com>
In reply to#16498
Richard Harter wrote:
> 
> The other day I wanted to put three successive question marks in a
> string.  Frex, "(???).%s.%s".  My trusty antique gcc compiler
> converted the last two '?'s into a ']' along with a warning that it
> was doing a trigraph conversion.
> 
> Now, me, I know from nothing about trigraphs - never used them, hope
> never to use them - so I was caught by surprise.  My elderly copy of
> K&R described them but I didn't see anything about getting around
> them.
> 
> So.  How is one supposed to get three successive question marks into a
> string?
> 

"(?""?""?).%s.%s\n"

-- 
pete

[toc] | [prev] | [next] | [standalone]


#16502

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2012-01-31 16:47 +0000
Message-ID<0.a671176e64755b2722e5.20120131164745GMT.87vcnrq0ni.fsf@bsb.me.uk>
In reply to#16499
pete <pfiland@mindspring.com> writes:

> Richard Harter wrote:
>> 
>> The other day I wanted to put three successive question marks in a
>> string.  Frex, "(???).%s.%s".  My trusty antique gcc compiler
>> converted the last two '?'s into a ']' along with a warning that it
>> was doing a trigraph conversion.
>> 
>> Now, me, I know from nothing about trigraphs - never used them, hope
>> never to use them - so I was caught by surprise.  My elderly copy of
>> K&R described them but I didn't see anything about getting around
>> them.
>> 
>> So.  How is one supposed to get three successive question marks into a
>> string?
>
> "(?""?""?).%s.%s\n"

That's possibly a bit "belt and braces".  "(??""?).%s.%s" will do.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#16507

Fromcri@tiac.net (Richard Harter)
Date2012-01-31 17:21 +0000
Message-ID<4f2821ac.654354243@text.giganews.com>
In reply to#16502
On Tue, 31 Jan 2012 16:47:45 +0000, Ben Bacarisse
<ben.usenet@bsb.me.uk> wrote:

>pete <pfiland@mindspring.com> writes:
>
>> Richard Harter wrote:
>>> 
>>> The other day I wanted to put three successive question marks in a
>>> string.  Frex, "(???).%s.%s".  My trusty antique gcc compiler
>>> converted the last two '?'s into a ']' along with a warning that it
>>> was doing a trigraph conversion.
>>> 
>>> Now, me, I know from nothing about trigraphs - never used them, hope
>>> never to use them - so I was caught by surprise.  My elderly copy of
>>> K&R described them but I didn't see anything about getting around
>>> them.
>>> 
>>> So.  How is one supposed to get three successive question marks into a
>>> string?
>>
>> "(?""?""?).%s.%s\n"
>
>That's possibly a bit "belt and braces".  "(??""?).%s.%s" will do.

That doesn't seem right to me, but what do I know.  As I read that
there are two strings there, to wit "(??" and "?).%s.%s".  Are you
telling me that two adjacent strings will be merged into one string.
If that's so I'm certainly surprised and I've learned something quite
unexpected.  Does this mean I can write  printf("x""y") and I will get
"xy" as an output?

[toc] | [prev] | [next] | [standalone]


#16508

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-01-31 12:26 -0500
Message-ID<4F282432.3060509@verizon.net>
In reply to#16507
On 01/31/2012 12:21 PM, Richard Harter wrote:
...
> ...  Are you
> telling me that two adjacent strings will be merged into one string.

Yes. This merger is the only thing that occurs during translation phase
6, which is described in section 5.1.1.2p6.

[toc] | [prev] | [next] | [standalone]


#16515

FromRobert Wessel <robertwessel2@yahoo.com>
Date2012-01-31 11:40 -0600
Message-ID<pj9gi79muj8eac7s030orq8uictgt44beg@4ax.com>
In reply to#16507
On Tue, 31 Jan 2012 17:21:37 GMT, cri@tiac.net (Richard Harter) wrote:

>On Tue, 31 Jan 2012 16:47:45 +0000, Ben Bacarisse
><ben.usenet@bsb.me.uk> wrote:
>
>>pete <pfiland@mindspring.com> writes:
>>
>>> Richard Harter wrote:
>>>> 
>>>> The other day I wanted to put three successive question marks in a
>>>> string.  Frex, "(???).%s.%s".  My trusty antique gcc compiler
>>>> converted the last two '?'s into a ']' along with a warning that it
>>>> was doing a trigraph conversion.
>>>> 
>>>> Now, me, I know from nothing about trigraphs - never used them, hope
>>>> never to use them - so I was caught by surprise.  My elderly copy of
>>>> K&R described them but I didn't see anything about getting around
>>>> them.
>>>> 
>>>> So.  How is one supposed to get three successive question marks into a
>>>> string?
>>>
>>> "(?""?""?).%s.%s\n"
>>
>>That's possibly a bit "belt and braces".  "(??""?).%s.%s" will do.
>
>That doesn't seem right to me, but what do I know.  As I read that
>there are two strings there, to wit "(??" and "?).%s.%s".  Are you
>telling me that two adjacent strings will be merged into one string.
>If that's so I'm certainly surprised and I've learned something quite
>unexpected.  Does this mean I can write  printf("x""y") and I will get
>"xy" as an output?


Yes.  C merges adjacent strings.  Probably seen most frequently when a
string is too long to fit conveniently on a single line.  Also with
macros used to add prefixes and suffixes to strings.  In C99 the
macros for the printf formatting codes for the stdint types are used
that way.

[toc] | [prev] | [next] | [standalone]


#16532

FromKeith Thompson <kst-u@mib.org>
Date2012-01-31 15:22 -0800
Message-ID<ln8vknxxs9.fsf@nuthaus.mib.org>
In reply to#16515
Robert Wessel <robertwessel2@yahoo.com> writes:
[...]
> Yes.  C merges adjacent strings.
[...]

C merges adjacent string *literals*.

For example, this:

    printf("hello" " world\n");

works, but this:

    const char s[] = "hello";
    printf(s " world\n");

is a syntax error.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#16540

From"BartC" <bc@freeuk.com>
Date2012-02-01 01:09 +0000
Message-ID<jga3da$nlc$1@dont-email.me>
In reply to#16532

"Keith Thompson" <kst-u@mib.org> wrote in message 
news:ln8vknxxs9.fsf@nuthaus.mib.org...
> Robert Wessel <robertwessel2@yahoo.com> writes:
> [...]
>> Yes.  C merges adjacent strings.
> [...]
>
> C merges adjacent string *literals*.
>
> For example, this:
>
>    printf("hello" " world\n");
>
> works, but this:
>
>    const char s[] = "hello";
>    printf(s " world\n");
>
> is a syntax error.

On the other hand, this works as expected:

#define s "hello"

printf(s " world\n");

Is s a string literal here?

-- 
Bartc
 

[toc] | [prev] | [next] | [standalone]


#16547

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-01-31 22:21 -0500
Message-ID<jgab3p$ore$1@dont-email.me>
In reply to#16540
On 01/31/2012 08:09 PM, BartC wrote:
> 
> 
> "Keith Thompson" <kst-u@mib.org> wrote in message 
> news:ln8vknxxs9.fsf@nuthaus.mib.org...
...
>> C merges adjacent string *literals*.
>>
>> For example, this:
>>
>>    printf("hello" " world\n");
>>
>> works, but this:
>>
>>    const char s[] = "hello";
>>    printf(s " world\n");
>>
>> is a syntax error.
> 
> On the other hand, this works as expected:
> 
> #define s "hello"
> 
> printf(s " world\n");
> 
> Is s a string literal here?

No, s is the name of a macro; but during translation phase 4 that macro
expands into a string literal.
-- 
James Kuyper

[toc] | [prev] | [next] | [standalone]


#16556

FromKeith Thompson <kst-u@mib.org>
Date2012-01-31 21:25 -0800
Message-ID<ln7h07w2f5.fsf@nuthaus.mib.org>
In reply to#16540
"BartC" <bc@freeuk.com> writes:
> "Keith Thompson" <kst-u@mib.org> wrote in message
> news:ln8vknxxs9.fsf@nuthaus.mib.org...
>> Robert Wessel <robertwessel2@yahoo.com> writes:
>> [...]
>>> Yes.  C merges adjacent strings.
>> [...]
>>
>> C merges adjacent string *literals*.
>>
>> For example, this:
>>
>>    printf("hello" " world\n");
>>
>> works, but this:
>>
>>    const char s[] = "hello";
>>    printf(s " world\n");
>>
>> is a syntax error.
>
> On the other hand, this works as expected:
>
> #define s "hello"
>
> printf(s " world\n");
>
> Is s a string literal here?

It is by the time adjacent string literals are merged.

Macro invocations are expanded in translation phase 4.  Adjacent string
literals are merged in translation phase 6.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#16557

From"Charles Richmond" <netnews@aquaporin4.com>
Date2012-01-31 23:40 -0600
Message-ID<jgaj81$ojt$1@dont-email.me>
In reply to#16532
"Keith Thompson" <kst-u@mib.org> wrote in message 
news:ln8vknxxs9.fsf@nuthaus.mib.org...
> Robert Wessel <robertwessel2@yahoo.com> writes:
> [...]
>> Yes.  C merges adjacent strings.
> [...]
>
> C merges adjacent string *literals*.
>
> For example, this:
>
>    printf("hello" " world\n");
>
> works, but this:
>
>    const char s[] = "hello";
>    printf(s " world\n");
>
> is a syntax error.
>

But you *can* do something like this, using the preprocessor:


#define   HELLO     "hello"
#define   WORLD   "world!!!\n"

    ...     ....      .....      .....

     printf(HELLO WORLD);

Keith, your sig might say "DO right code for food."  After all, if 
programming in C is your occupation, that is basically what you are doing. 
:-)


-- 
+<><><><><><><><><><><><><><><><><><><>+
|      Charles Richmond       numerist@aquaporin4.com     |
+<><><><><><><><><><><><><><><><><><><>+ 

[toc] | [prev] | [next] | [standalone]


#16566

FromKeith Thompson <kst-u@mib.org>
Date2012-01-31 22:19 -0800
Message-ID<lny5snulbn.fsf@nuthaus.mib.org>
In reply to#16557
"Charles Richmond" <netnews@aquaporin4.com> writes:
> "Keith Thompson" <kst-u@mib.org> wrote in message 
> news:ln8vknxxs9.fsf@nuthaus.mib.org...
>> Robert Wessel <robertwessel2@yahoo.com> writes:
>> [...]
>>> Yes.  C merges adjacent strings.
>> [...]
>>
>> C merges adjacent string *literals*.
>>
>> For example, this:
>>
>>    printf("hello" " world\n");
>>
>> works, but this:
>>
>>    const char s[] = "hello";
>>    printf(s " world\n");
>>
>> is a syntax error.
>>
>
> But you *can* do something like this, using the preprocessor:
>
>
> #define   HELLO     "hello"
> #define   WORLD   "world!!!\n"
>
>     ...     ....      .....      .....
>
>      printf(HELLO WORLD);

Sure, but that doesn't work if the strings are not compile-time constant
values.  There's no way to use string concatenation to do something like
this:

    char line[80];
    fgets(line, sizeof line, stdin);
    puts("line = " line);

> Keith, your sig might say "DO right code for food."  After all, if 
> programming in C is your occupation, that is basically what you are doing. 
> :-)

<OT>It's a reference to the "Will work for food" signs that some
homeless/unemployed people carry.  I'm currently unemployed.</OT>

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#16588

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-02-01 08:27 -0500
Message-ID<jgbekc$ojq$1@dont-email.me>
In reply to#16566
On 02/01/2012 01:19 AM, Keith Thompson wrote:
...
> <OT>It's a reference to the "Will work for food" signs that some
> homeless/unemployed people carry.  I'm currently unemployed.</OT>

If you're serious about "Will write code for food", you should provide a
link that leads to your resume.
-- 
James Kuyper

[toc] | [prev] | [next] | [standalone]


#16517

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2012-01-31 17:47 +0000
Message-ID<0.917aa078b4fe73b05b64.20120131174737GMT.87d39zpxvq.fsf@bsb.me.uk>
In reply to#16507
cri@tiac.net (Richard Harter) writes:

> On Tue, 31 Jan 2012 16:47:45 +0000, Ben Bacarisse
> <ben.usenet@bsb.me.uk> wrote:
>
>>pete <pfiland@mindspring.com> writes:
>>
>>> Richard Harter wrote:
>>>> 
>>>> The other day I wanted to put three successive question marks in a
>>>> string.  Frex, "(???).%s.%s".  My trusty antique gcc compiler
>>>> converted the last two '?'s into a ']' along with a warning that it
>>>> was doing a trigraph conversion.
>>>> 
>>>> Now, me, I know from nothing about trigraphs - never used them, hope
>>>> never to use them - so I was caught by surprise.  My elderly copy of
>>>> K&R described them but I didn't see anything about getting around
>>>> them.
>>>> 
>>>> So.  How is one supposed to get three successive question marks into a
>>>> string?
>>>
>>> "(?""?""?).%s.%s\n"
>>
>>That's possibly a bit "belt and braces".  "(??""?).%s.%s" will do.
>
> That doesn't seem right to me, but what do I know.  As I read that
> there are two strings there, to wit "(??" and "?).%s.%s".  Are you
> telling me that two adjacent strings will be merged into one string.

Yes.

> If that's so I'm certainly surprised and I've learned something quite
> unexpected.  Does this mean I can write  printf("x""y") and I will get
> "xy" as an output?

Yup.  It's not an uncommon idiom.  For example, it's used by the print
format macros in inttypes.h.  PRId64 is a string with the correct format
for an int64_t: printf("%10"PRId64"\n", x); You can also use it to
interpolate a macro into a string to make scanf("%" TO_STR(SIZE) "s"...)
safe.  (But note that the target must be of size SIZE+1.)

C translation occurs in a number of phases.  Trigraphs are translated in
phase 1 and adjacent string literals are fused in phase 6 (after macro
expansion in phase 4) so simply splitting a trigraph is enough.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#16518

FromImpalerCore <jadill33@gmail.com>
Date2012-01-31 09:41 -0800
Message-ID<46dbfc63-8800-40f2-a6c9-f37b99c9b27c@dn8g2000vbb.googlegroups.com>
In reply to#16507
On Jan 31, 12:21 pm, c...@tiac.net (Richard Harter) wrote:
> On Tue, 31 Jan 2012 16:47:45 +0000, Ben Bacarisse
>
>
>
>
>
>
>
>
>
> <ben.use...@bsb.me.uk> wrote:
> >pete <pfil...@mindspring.com> writes:
>
> >> Richard Harter wrote:
>
> >>> The other day I wanted to put three successive question marks in a
> >>> string.  Frex, "(???).%s.%s".  My trusty antique gcc compiler
> >>> converted the last two '?'s into a ']' along with a warning that it
> >>> was doing a trigraph conversion.
>
> >>> Now, me, I know from nothing about trigraphs - never used them, hope
> >>> never to use them - so I was caught by surprise.  My elderly copy of
> >>> K&R described them but I didn't see anything about getting around
> >>> them.
>
> >>> So.  How is one supposed to get three successive question marks into a
> >>> string?
>
> >> "(?""?""?).%s.%s\n"
>
> >That's possibly a bit "belt and braces".  "(??""?).%s.%s" will do.
>
> That doesn't seem right to me, but what do I know.  As I read that
> there are two strings there, to wit "(??" and "?).%s.%s".  Are you
> telling me that two adjacent strings will be merged into one string.
> If that's so I'm certainly surprised and I've learned something quite
> unexpected.  Does this mean I can write  printf("x""y") and I will get
> "xy" as an output?

Yep.  That behavior is actually required to use PRI fprintf macros.

printf( "INT32_MIN = %" PRId32 ", INT32_MAX = %" PRId32 "\n",
        INT32_MIN, INT32_MAX  );

where PRId32 may be defined to "d" or "ld" or "I32d" or whatever
string is needed.

Best regards,
John D.

[toc] | [prev] | [next] | [standalone]


#16521

Frompete <pfiland@mindspring.com>
Date2012-01-31 13:17 -0500
Message-ID<4F283030.2E84@mindspring.com>
In reply to#16507
Richard Harter wrote:
 
> That doesn't seem right to me, but what do I know.  As I read that
> there are two strings there, to wit "(??" and "?).%s.%s".  Are you
> telling me that two adjacent strings will be merged into one string.
> If that's so I'm certainly surprised and I've learned something quite
> unexpected.  Does this mean I can write  printf("x""y") and I will get
> "xy" as an output?

/*
** You can also use this feature
** to place the value of a macro inside a string.
*/
#include <stdio.h>

#define macro_value         the value of a macro
#define str(s)              # s
#define xstr(s)             str(s)

int 
main(void) 
{    
    puts(
        "You can also use this feature\nto place "
        xstr(macro_value)
        " inside a string."
        );
    return 0;
}

-- 
pete

[toc] | [prev] | [next] | [standalone]


#16520

Fromblp@cs.stanford.edu (Ben Pfaff)
Date2012-01-31 09:56 -0800
Message-ID<87k44792nt.fsf@blp.benpfaff.org>
In reply to#16498
cri@tiac.net (Richard Harter) writes:

> So.  How is one supposed to get three successive question marks into a
> string?

??? works fine.  You only have a problem because of the character
following the last ?.  Given that, you can use "" to break up the
question marks, or use \?.

The C99 Rationale says:

      The character escape sequence '\?' (see §6.4.4.4) was
      introduced to allow two adjacent question marks in such
      contexts to be represented as ?\?, a form distinct from the
      escape digraph.
-- 
"I've been on the wagon now for more than a decade. Not a single goto
 in all that time. I just don't need them any more. I don't even use
 break or continue now, except on social occasions of course. And I
 don't get carried away." --Richard Heathfield

[toc] | [prev] | [next] | [standalone]


#16526

FromPeter Nilsson <airia@acay.com.au>
Date2012-01-31 13:55 -0800
Message-ID<f34c5985-fa61-45bc-bc32-c337b949beb7@3g2000pbd.googlegroups.com>
In reply to#16498
c...@tiac.net (Richard Harter) wrote:
> The other day I wanted to put three successive question marks in a
> string.  Frex, "(???).%s.%s".  My trusty antique gcc compiler
> converted the last two '?'s into a ']' along with a warning that
> it was doing a trigraph conversion.
> ...
> So.  How is one supposed to get three successive question marks
> into a string?

Simple. You put three successive question marks in a string. ;)
E.g. "(" "???" ").%s.%s".

As you know, the issue is not a sequence of three question marks,
but the ) that follows the last two. Old MacOS programmers
encountered the trigraph issue with the character constant '????'.
The adopted idiom was to use '???\?'. Whilst it looks wierd at
first sight, Mac programmers wouldn't bat an eyelid at it.

--
Peter

[toc] | [prev] | [next] | [standalone]


#16527

FromHarald van Dijk <haraldvdijk@gmail.com>
Date2012-01-31 14:02 -0800
Message-ID<169ba5f6-d289-433e-824a-456e402b2342@do4g2000vbb.googlegroups.com>
In reply to#16526
On Jan 31, 10:55 pm, Peter Nilsson <ai...@acay.com.au> wrote:
> Old MacOS programmers
> encountered the trigraph issue with the character constant '????'.
> The adopted idiom was to use '???\?'. Whilst it looks wierd at
> first sight, Mac programmers wouldn't bat an eyelid at it.

Out of curiosity: what is the correct way to avoid this?
Multicharacter constants are implementation-specific but valid in
standard C, and at the same time \? is not. I can only come up with

'???\
?'

but that seems more complicated than should be necessary.

[toc] | [prev] | [next] | [standalone]


#16528

Fromblp@cs.stanford.edu (Ben Pfaff)
Date2012-01-31 14:06 -0800
Message-ID<87fwev8r37.fsf@blp.benpfaff.org>
In reply to#16527
Harald van Dijk <haraldvdijk@gmail.com> writes:

> Multicharacter constants are implementation-specific but valid in
> standard C, and at the same time \? is not.

\? is a valid escape sequence in a character or string constant
in standard C, since C89.
-- 
"When in doubt, treat ``feature'' as a pejorative.
 (Think of a hundred-bladed Swiss army knife.)"
--Kernighan and Plauger, _Software Tools_

[toc] | [prev] | [next] | [standalone]


Page 1 of 3  [1] 2 3  Next page →

Back to top | Article view | comp.lang.c


csiph-web