473,387 Members | 1,561 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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.

Apr 7 '06 #1
4 1177
NC
wo********@yahoo.ca wrote:

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.


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

Apr 7 '06 #2
NC wrote:
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...


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

Apr 7 '06 #3
A constants.ini (or whatever) file which is read by C and PHP could be
used too I guess.

Apr 8 '06 #4
On Fri, 07 Apr 2006 07:02:53 -0700, wong_powah wrote:
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.


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.

--
http://www.mgogala.com

Apr 8 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andrea M. Segovia | last post by:
I just compiled (but did not install) perl 5.8.0 on an SGI Origin 300 server (IP35) running IRIX 6.5.20m. Make test reported one test error, which I narrowed down to .../lib/ExUtils/t/Constant.t...
6
by: fctk | last post by:
hello, i'm trying to compile this small program: int main(void) { unsigned long int max; max = 4000000000;
25
by: tsaar2003 | last post by:
Hi Pythonians, To begin with I'd like to apologize that I am not very experienced Python programmer so please forgive me if the following text does not make any sense. I have been missing...
3
by: lovecreatesbeauty | last post by:
Both `K&R C, 2nd' and `C: A reference manual, 5th' introduce the "hello, world" thing using the name "string-constant". But `ISO/IEC 9899:TC2' does not include this kind of thing in section `A.1.5...
25
by: galapogos | last post by:
Hi, I'm trying to compare an array of unsigned chars(basically just data without any context) with a constant, and I'm not sure how to do that. Say my array is array and I want to compare it with...
33
by: desktop | last post by:
In the C++ standard sec 23.1.2 table 69 it says that erase(q) where q is a pointer to an element can be done in amortized constant time. I guess that is not worst case since std::set is...
18
by: sinbad | last post by:
hi, why does the following program gives an runtime error ,instead of compilation error. anyone please shed some light. thanks sinbad ------------------------------ int main()
3
by: Dan Smithers | last post by:
What constitutes a constant-expression? I know that it is something that can be determined at compile time. I am trying to use template code and keep getting compiler errors "error: cannot...
7
by: John Koleszar | last post by:
Hi all, I'm porting some code that provides compile-time assertions from one compiler to another and ran across what I believe to be compliant code that won't compile using the new compiler. Not...
7
by: Hendrik Schober | last post by:
Hi, this #include <string> class test { typedef std::string::size_type size_type; static const size_type x = std::string::npos; }; doesn't compile using either VC9 ("expected constant...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.