<div class="gmail_quote">I see what your saying.<br><br>Is there another way of declaring (at least) the docstring apart from the actual array?(it would get messy otherwise)<br><br>I had also tried defining the variables as static but got the same result (I thought static meant in code memory instead of the heap...?)<br>

<br>I am new to C so I may just be going about this all wrong...<div class="im"><br><br clear="all">-- Maranatha!<br>---------------------------------<br>PFC aka Fezzik aka GAB<br>
<br><br></div><div><div></div><div class="h5"><div class="gmail_quote">On Fri, Nov 27, 2009 at 10:25 PM, MRAB <span dir="ltr"><<a href="mailto:python@mrabarnett.plus.com" target="_blank">python@mrabarnett.plus.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
P.F.C. wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div>
Hello, I'm new to the mailing list but have been using python for a while.<br>
<br>
I am now attempting to embed the interpreter into a C application but am having an issue when building a module exposing my application's functions to python.<br>
I do not know if this is the right place to ask for help with it, if it isn't then please let me know where to go.<br>
<br>
the problem I'm having is with making a PyMethodDef array<br>
When I make the array like this it works:<br>
<br>
static PyMethodDef ge_methods[]={<br>
  {"test",ge_test,METH_NOARGS,"Test returns 123L"},<br>
  {NULL,NULL}<br>
};<br>
<br>
but as soon as I try to build the array from constant variables like this:<br>
<br>
const int ge_test_args = METH_NOARGS;                       //The flag for this function<br>
const char* ge_test_doc = "Test\nwill print \"test\"";        //The docstring<br>
static PyMethodDef ge_methods[]={<br>
   {"test",ge_test, ge_test_args, ge_test_doc},                //simply replacing the flag and the docstring with a constant variable<br>
   {NULL,NULL}<br>
};<br>
<br>
the compiler then gives the following errors:<br>
./test1.c:74: error: initializer element is not constant<br>
./test1.c:74: error: (near initialization for ‘ge_methods[0].ml_flags’)<br>
./test1.c:74: error: initializer element is not constant<br>
./test1.c:74: error: (near initialization for ‘ge_methods[0].ml_doc’)<br>
<br>
I'm using the gcc compiler<br>
<br>
This may well be because of my lack of understanding the C language but I was hoping someone could help me out, or at least point me in the right direction<br>
<br></div></div>
I also posted about this at <a href="http://talk.christiandevs.com/viewtopic.php?f=13&t=2521" target="_blank">http://talk.christiandevs.com/viewtopic.php?f=13&t=2521</a> <<a href="http://talk.christiandevs.com/viewtopic.php?f=13&t=2521" target="_blank">http://talk.christiandevs.com/viewtopic.php?f=13&t=2521</a>><br>


<br>
</blockquote>
I think it's because C 'const' objects aren't true constants, but are<br>
more like read-only variables; you can initialise them in the<br>
declaration but not assign to them otherwise. Thus what you're actually<br>
trying to do is initialise from a variable, not a constant.<br><font color="#888888">
-- <br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br>
</div></div></div><br>