use C constant in php

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • wong_powah@yahoo.ca

    #1

    use C constant in php

    I define some constants in C header file.
    e.g.
    const int MAX = 10;

    How do I use the same value of MAX in php without redefining MAX in
    php?
    i.e. it involve how php interact with functions and libraries written
    in other languages, such as C.

  • NC

    #2
    Re: use C constant in php

    wong_powah@yaho o.ca wrote:[color=blue]
    >
    > I define some constants in C header file.
    > e.g.
    > const int MAX = 10;
    >
    > How do I use the same value of MAX in php without redefining
    > MAX in php?
    > i.e. it involve how php interact with functions and libraries written
    > in other languages, such as C.[/color]

    Generally speaking, PHP cannot interact with random code. If you want
    PHP to use entities defined in C, you must write a PHP extension and
    ensure PHP is configured to use that extension.

    Alternatively, you could just have your C program set some environment
    variables; they will be accessible to PHP as members of the $_ENV
    superglobal array.

    Other alternatives include using shared memory (only on Unix) and
    wrapping your C program into a Web service...

    Cheers,
    NC

    Comment

    • Toby Inkster

      #3
      Re: use C constant in php

      NC wrote:
      [color=blue]
      > Alternatively, you could just have your C program set some environment
      > variables; they will be accessible to PHP as members of the $_ENV
      > superglobal array.
      >
      > Other alternatives include using shared memory (only on Unix) and
      > wrapping your C program into a Web service...[/color]

      Or the OP could try writing some PHP to parse the C code (or the
      particular bits of C code that are required)

      --
      Toby A Inkster BSc (Hons) ARCS
      Contact Me ~ http://tobyinkster.co.uk/contact

      Comment

      • Mike Youell

        #4
        Re: use C constant in php

        A constants.ini (or whatever) file which is read by C and PHP could be
        used too I guess.

        Comment

        • Mladen Gogala

          #5
          Re: use C constant in php

          On Fri, 07 Apr 2006 07:02:53 -0700, wong_powah wrote:
          [color=blue]
          > I define some constants in C header file.
          > e.g.
          > const int MAX = 10;
          >
          > How do I use the same value of MAX in php without redefining MAX in
          > php?
          > i.e. it involve how php interact with functions and libraries written
          > in other languages, such as C.[/color]

          The statement

          define('MAX',10 );

          would do the same thing. The "int" part is impossible, due to the weakly
          typed nature of PHP. As for interacting with other languages, read the
          manuals, they describe how to write an extension.

          --
          大红鹰娱乐平台采用顶级加密技术,确保用户数据与交易的安全无虞,让玩家能够放心畅玩。


          Comment

          Working...