public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <pedro_alves@portugalmail.pt>
To: Pedro Alves <pedro_alves@portugalmail.pt>
Cc: Hans-Peter Nilsson <hans-peter.nilsson@axis.com>,
	 nickc@redhat.com,   binutils@sourceware.org
Subject: Re: [PATCH]: Re: Regression with strn-stuff
Date: Tue, 19 Sep 2006 10:37:00 -0000	[thread overview]
Message-ID: <450F30AC.90200@portugalmail.pt> (raw)
In-Reply-To: <450DCA2B.30202@portugalmail.pt>


>>> The double double-quotes ("") were there to check if the parameter
>>> was a compile time const string, since it is legal in C to write a 
>>> string this way:
>>> ("string part 1" "string part 2").
>>>     Isn't the double quotes version OK?
>>>     
>>
>>>>   
> Attached is a patch to do just that.

(...)

> If this turns out to be too limiting, we will indeed have to turn
> to __builtin_constant_p for gcc...
> 
> Please (test,) review, and commit.
> 

I withdraw this patch. I found some places where this was too
limiting. It turns out that in some places the ()'s around
the passed in string literal were really needed,
making ("a string") "" uncompilable.
I don't think there is any way in C to implement the
REMOVE_PARENS macro below, is there?

#define REMOVE_PARENS(S) (?)
REMOVE_PARENS(("a string")) => "A STRING"

Cheers,
Pedro Alves


> 
> ---
> bfd/ChangeLog
> 
> 2006-09-17  Pedro Alves  <pedro_alves@portugalmail.pt>
> 
> 
>    * bfd-in.h (CONST_STRNEQ): Make it error out if STR2 is not a compile 
> time constant string.
>    (CONST_STRNCPY): Likewise.
>    * bfd-in2.h: Regenerate.
> 
> 
> ------------------------------------------------------------------------
> 
> Index: bfd-in.h
> ===================================================================
> RCS file: /cvs/src/src/bfd/bfd-in.h,v
> retrieving revision 1.117
> diff -u -p -r1.117 bfd-in.h
> --- bfd-in.h	16 Sep 2006 18:12:13 -0000	1.117
> +++ bfd-in.h	17 Sep 2006 21:59:33 -0000
> @@ -57,9 +57,13 @@ extern "C" {
>     the arguments to the strncmp() macro.  Hence this alternative
>     definition of strncmp is provided here.
>     
> -   Note - these macros do NOT work if STR2 is not a constant string.  */
> -#define CONST_STRNEQ(STR1,STR2) (strncmp ((STR1), (STR2), sizeof (STR2) - 1) == 0)
> -#define CONST_STRNCPY(STR1,STR2) strncpy ((STR1), (STR2), sizeof (STR2) - 1)
> +   Note - the double double-quotes ("") are there to ensure that
> +   STR2 is a compile-time constant string. 
> +   This works, because in C it is possible to define a string
> +   in parts like in:
> +   const char* str = "str part 1" "str part 2";  */
> +#define CONST_STRNEQ(STR1,STR2) (strncmp (STR1, STR2 "", sizeof (STR2) - 1) == 0)
> +#define CONST_STRNCPY(STR1,STR2) strncpy (STR1, STR2 "", sizeof (STR2) - 1)
>  
>  
>  /* The word size used by BFD on the host.  This may be 64 with a 32

  reply	other threads:[~2006-09-18 23:49 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-11 21:03 [PATCH] Make the compiler do the math 2 Pedro Alves
2006-09-12 11:27 ` Pedro Alves
2006-09-16 18:16   ` Nick Clifton
2006-09-17  3:39     ` Regression with strn-stuff (was: Re: [PATCH] Make the compiler do the math 2.) Hans-Peter Nilsson
2006-09-17 14:41       ` Regression with strn-stuff Nick Clifton
2006-09-17 18:58         ` Pedro Alves
2006-09-17 19:17           ` Hans-Peter Nilsson
2006-09-17 22:20             ` [PATCH]: " Pedro Alves
2006-09-19 10:37               ` Pedro Alves [this message]
2006-09-25 16:14                 ` Nick Clifton
2006-09-25 16:19                 ` Andreas Schwab
2006-09-17 19:08         ` Hans-Peter Nilsson
2006-09-25 16:09           ` Nick Clifton
2006-09-25 14:01     ` [PATCH] Make the compiler do the math 2 Andreas Schwab
2006-09-25 17:14       ` Nick Clifton
2006-09-25 19:37         ` Andreas Schwab
2006-09-25 20:38       ` Hans-Peter Nilsson
2006-09-25 22:23         ` Andreas Schwab
2006-09-26  8:49           ` Nick Clifton
2006-09-26 10:17           ` Nick Clifton
2006-09-26 10:30             ` Andreas Schwab
2006-09-26 12:38             ` Pedro Alves
2006-09-25 23:53         ` Pedro Alves
2006-09-28 13:25           ` Nick Clifton

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=450F30AC.90200@portugalmail.pt \
    --to=pedro_alves@portugalmail.pt \
    --cc=binutils@sourceware.org \
    --cc=hans-peter.nilsson@axis.com \
    --cc=nickc@redhat.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 read-only IMAP folder(s) and NNTP newsgroup(s).