FAQ
Hi all,

I'm a C newbie and just started experimenting with the PHP internals a
couple weeks ago... A few days ago I noticed assignment/comparison of char
variables to '' (nothing between single quotes) in, for example, the
is_numeric_string function (zend_operators.h), snprintf.c, spprintf.c, etc.
I don't understand what it's doing. :-/ The only references I can find are
about "empty character constant" compiler errors, which is what happens if I
try to use '' in the same way (VC++ Express). Though PHP compiles fine with
these "constructs," so something must be special there?

Sorry to bother the list with this if it's a general C thing that should be
known and not PHP-code specific. But I've tried to figure it out on my own
(which I have with other stuff so far :-)) and can't, so I'd appreciate it
if someone can clue me in!


Thanks,
Matt

Search Discussions

  • Pierre at Jul 8, 2006 at 9:18 am

    On 7/8/06, Matt W wrote:
    Hi all,

    I'm a C newbie and just started experimenting with the PHP internals a
    couple weeks ago... A few days ago I noticed assignment/comparison of char
    variables to '' (nothing between single quotes) in, for example, the
    is_numeric_string function (zend_operators.h), snprintf.c, spprintf.c, etc.
    I don't understand what it's doing. :-/ The only references I can find are
    about "empty character constant" compiler errors, which is what happens if I
    try to use '' in the same way (VC++ Express). Though PHP compiles fine with
    these "constructs," so something must be special there?
    http://publications.gbdirect.co.uk/c_book/chapter5/character_handling.html

    Cheers,
    --Pierre
  • Matt W at Jul 8, 2006 at 9:50 am
    Hi Pierre,

    Thanks for the reply, but where does that page talk about an EMPTY character
    constant? I pretty much understand character handling otherwise. :-)


    Thanks,
    Matt


    ----- Original Message -----
    From: "Pierre"
    Subject: Re: [PHP-DEV] Use of "empty character constant?"

    On 7/8/06, Matt W wrote:
    Hi all,

    I'm a C newbie and just started experimenting with the PHP internals a
    couple weeks ago... A few days ago I noticed assignment/comparison of
    char
    variables to '' (nothing between single quotes) in, for example, the
    is_numeric_string function (zend_operators.h), snprintf.c, spprintf.c,
    etc.
    I don't understand what it's doing. :-/ The only references I can find
    are
    about "empty character constant" compiler errors, which is what happens
    if I
    try to use '' in the same way (VC++ Express). Though PHP compiles fine
    with
    these "constructs," so something must be special there?
    http://publications.gbdirect.co.uk/c_book/chapter5/character_handling.html

    Cheers,
    --Pierre
  • Pierre at Jul 8, 2006 at 10:32 am

    On 7/8/06, Matt W wrote:
    Hi Pierre,

    Thanks for the reply, but where does that page talk about an EMPTY character
    constant? I pretty much understand character handling otherwise. :-)
    Then I do not understand your question. Do you have the exact
    error/warning/notice? And some example code?

    --Pierre
  • Matt W at Jul 8, 2006 at 10:48 am
    Hi Pierre,

    :-O I was just going to give you an example from zend_operators.h,
    is_numeric_string() and guess what? It's the "correct" way that I thought
    it should be! I thought PHP 6 changed something, to where

    /* handle hex numbers */
    if (length>=2 && str[0]=='0' && (str[1]=='x' || str[1]=='X')) {
    conv_base=16;
    }

    which is easy to understand :-) became

    if (length>=2 && str[0]=='' && (str[1]=='x' || str[1]=='X')) {
    conv_base=16;
    }

    BUT, I recently started looking at http://lxr.php.net so I could
    cross-reference, etc., instead of searching my local sources, and that's
    where I first saw this "change." It took you asking for an example for me
    to realize that LXR is the problem, screwing up the display of '0' !
    (Though I *think* I saw it correctly in some places?) LOL, I can't believe
    it. I kinda thought, "Oh well, I just don't get it," but I'm glad I
    e-mailed before spending more time than I have trying to figure out what the
    empty char constant does!

    http://lxr.php.net/ident?i=is_numeric_string -- check out 12 lines into the
    function definition. :-/

    Well, thanks for helping me get on the right track to "solving" this. The
    LXR thing needs fixing I guess.


    Matt


    ----- Original Message -----
    From: "Pierre"
    Subject: Re: [PHP-DEV] Use of "empty character constant?"

    On 7/8/06, Matt W wrote:
    Hi Pierre,

    Thanks for the reply, but where does that page talk about an EMPTY
    character
    constant? I pretty much understand character handling otherwise. :-)
    Then I do not understand your question. Do you have the exact
    error/warning/notice? And some example code?

    --Pierre
  • Antony Dovgal at Jul 8, 2006 at 11:02 am

    On 08.07.2006 14:48, Matt W wrote:
    Hi Pierre,

    :-O I was just going to give you an example from zend_operators.h,
    is_numeric_string() and guess what? It's the "correct" way that I thought
    it should be! I thought PHP 6 changed something, to where

    /* handle hex numbers */
    if (length>=2 && str[0]=='0' && (str[1]=='x' || str[1]=='X')) {
    conv_base=16;
    }

    which is easy to understand :-) became

    if (length>=2 && str[0]=='' && (str[1]=='x' || str[1]=='X')) {
    conv_base=16;
    }
    '0' became '' ?
    Why would _character_ 0 become nothing?

    --
    Wbr,
    Antony Dovgal
  • Matt W at Jul 8, 2006 at 11:10 am
    Hi Antony,

    ----- Original Message -----
    From: "Antony Dovgal"

    On 08.07.2006 14:48, Matt W wrote:
    Hi Pierre,

    :-O I was just going to give you an example from zend_operators.h,
    is_numeric_string() and guess what? It's the "correct" way that I
    thought
    it should be! I thought PHP 6 changed something, to where

    /* handle hex numbers */
    if (length>=2 && str[0]=='0' && (str[1]=='x' || str[1]=='X')) {
    conv_base=16;
    }

    which is easy to understand :-) became

    if (length>=2 && str[0]=='' && (str[1]=='x' || str[1]=='X')) {
    conv_base=16;
    }
    '0' became '' ?
    Why would _character_ 0 become nothing?
    I don't know; was wondering the same thing. :-) But, that is what I saw on
    http://lxr.php.net :-(


    Matt
  • Antony Dovgal at Jul 8, 2006 at 11:37 am

    On 08.07.2006 15:10, Matt W wrote:
    Hi Antony,

    ----- Original Message -----
    From: "Antony Dovgal"

    On 08.07.2006 14:48, Matt W wrote:
    Hi Pierre,

    :-O I was just going to give you an example from zend_operators.h,
    is_numeric_string() and guess what? It's the "correct" way that I
    thought
    it should be! I thought PHP 6 changed something, to where

    /* handle hex numbers */
    if (length>=2 && str[0]=='0' && (str[1]=='x' || str[1]=='X')) {
    conv_base=16;
    }

    which is easy to understand :-) became

    if (length>=2 && str[0]=='' && (str[1]=='x' || str[1]=='X')) {
    conv_base=16;
    }
    '0' became '' ?
    Why would _character_ 0 become nothing?
    I don't know; was wondering the same thing. :-) But, that is what I saw on
    http://lxr.php.net :-(
    What do you mean "I saw on lxr"?
    I still don't understand a word..

    --
    Wbr,
    Antony Dovgal
  • Matt W at Jul 8, 2006 at 11:28 am
    Hi Antony,

    ----- Original Message -----
    From: "Antony Dovgal"

    On 08.07.2006 15:10, Matt W wrote:
    Hi Antony,

    ----- Original Message -----
    From: "Antony Dovgal"
    '0' became '' ?
    Why would _character_ 0 become nothing?
    I don't know; was wondering the same thing. :-) But, that is what I saw
    on
    What do you mean "I saw on lxr"?
    I still don't understand a word..
    Didn't you see my explanation in the e-mail you first replied to? :-)
    http://lxr.php.net/source/ZendEngine2/zend_operators.h#82

    That's where I saw that " '0' became '' " The LXR code-cross-referencing
    thing wrongly displays '0' , which was the cause of my confusion.


    Matt
  • Antony Dovgal at Jul 10, 2006 at 11:11 am

    On 08.07.2006 15:28, Matt W wrote:
    Didn't you see my explanation in the e-mail you first replied to? :-)
    http://lxr.php.net/source/ZendEngine2/zend_operators.h#82

    That's where I saw that " '0' became '' " The LXR code-cross-referencing
    thing wrongly displays '0' , which was the cause of my confusion.
    Please report it to LXR developers: http://lxr.linux.no/

    --
    Wbr,
    Antony Dovgal
  • Michael Wallner at Jul 8, 2006 at 10:47 am

    Matt W wrote:
    Hi all,

    I'm a C newbie and just started experimenting with the PHP internals
    a couple weeks ago... A few days ago I noticed assignment/comparison
    of char variables to '' (nothing between single quotes) in, for
    example, the is_numeric_string function (zend_operators.h),
    snprintf.c, spprintf.c, etc. I don't understand what it's doing. :-/
    I don't see what you're seeing and cannot find a single occurrence of ''.

    --
    Michael
  • Mike Dransfield at Jul 10, 2006 at 11:07 am

    Michael Wallner wrote:
    Matt W wrote:
    Hi all,

    I'm a C newbie and just started experimenting with the PHP internals
    a couple weeks ago... A few days ago I noticed assignment/comparison
    of char variables to '' (nothing between single quotes) in, for
    example, the is_numeric_string function (zend_operators.h),
    snprintf.c, spprintf.c, etc. I don't understand what it's doing. :-/
    I don't see what you're seeing and cannot find a single occurrence of ''.

    http://lxr.php.net/source/ZendEngine2/zend_operators.h#71

    I think he is talking about this, it appears as '' on lxr

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedJul 8, '06 at 9:12a
activeJul 10, '06 at 11:11a
posts12
users5
websitephp.net

People

Translate

site design / logo © 2022 Grokbase