Hi Gary,
On Sun, Jan 22, 2012 at 11:57:44AM -0500, Gary Fisher wrote:
> >>> What does "return (static char *)Null" mean?
>> My mistake...I meant "return (const char *)Null" ... not static....and yes
> I do believe NULL is used in C++. At least the compiler didn't witch at me
> for it.
There's still no reason for the cast. And while you use 'NULL'
in C quite often it's frowned upon in C++. All you really need
is
return 0;
Since the compiler knows that the function returns a 'const char *'
it will automatically do the conversion. By casting (and then
even using a C-style cast, which is strongly discouraged in C++)
you tell the compiler "I know better than you" and you shouldn't
do that unless there's something the compiler can't figure out
on his own since a) you keep the compiler from explaining about
stuff that shouldn't/can't be done (don't see compiler complaints
as a nuisance but as a valuable help you to write correct pro-
grams) and b) you make the next person reading your code wonder
what this is all about.
> When I use "nm -C libword.so" on my little wrapped library I see nothing in
> the output to suggest a "word" class or a "reverse" method.
And that's at the very heart of your problem: the symbols needed
by the wrapper script don't exist in 'libword.so'. Rhe reason is
that there's not the slightest bit of necessity for the compiler/
linker to put them in there: you have a class declared with in-
lined methods that is never used anywhere. So there's no reason
to use the class for anything and it simply gets thrown out.
Every program using your library would include a header file for
the library that defines the interface. And while doing so it
would see the declaration of the class and would construct it's
own version of the class when it's needed.
I'm a bit at a loss at understanding how you got your SIP wrapper
to work without a header file, but that's another topic;-)
The quick fix is to simply splitting the word.cpp file up into
two parts, the necessary header file with the class declaration
and a cpp file with the function definitions. I.e. something
like this:
------- word.hpp -----------------------------
#ifndef WORD_HPP_
#define WORD_HPP_
class Word {
public:
Word( const char * w );
const char * reverse( );
private:
const char * the_word;
};
#endif
------- word.cpp -----------------------------
#include "word.hpp"
Word::Word( const char * w ) :
the_word( w )
{ }
const char *
Word::reverse( )
{
return 0;
}
----------------------------------------------
BTW: don't forget the 'public:' in the class!
If you now compile this into a shared library it will con-
tain both the symbols for the constructor and the reverse()
method. And within the SIP wrapper you include the 'word.hpp'
header file.
However, when
> I run "nm -C word.so" against the library generated by make I get things
> like:
>> 000021b4 d methods_Word
> U Word::Word(char const*)
> U Word::reverse() const
>> among other things.
Yes, the 'word.so' library needs those symbols and expects
them in one of the libraries it was linked with, but they
aren't anywhere. That will be only noticed when Python tries
to load the 'word.so' library and thus it fails.
BTW, the code in your program looks a bit broken.
> class Word {
> const char *the_word;
> // const char *the_reverse;
> char buffer[20], *pb;
>> int i, len;
>> Word( const char *w) {
> the_word = w;
> }
Do you realize that 'the_word' is now set to some memory
that doesn't belong to this class? It looks as if you
would like to store a word using this class, but that's
not what you do - all you keep is a pointer to some
string somewhere else in memory (and not owned by the
class instance). And if this memory is used for something
else then the 'the_word' pointer will point to memory that
doesn't contain a string anymore. I guess you're coming from
languages where memory allocation is done for you in the
background (like in Python), but if you write in C++ (or C)
you will have to be very careful to do the right thing with
memory, e.g. just holding a pointer to some memory doesn't
make it "yours" - you have to ensure that nothing else will
fiddle with the memory pointed to.
> const char *reverse () {
>> return (const char *) NULL;
>> /************************
> len = strlen(the_word);
> strcpy (buffer, the_word);
What happens if what 'the_word' points to is longer than 19
chars? You write past the end of buffer with unforseeable
effects. In the worst case it even might seem to work at
firt until some strange and hard to trace erros show up
much later...
> pb = (char *)the_word;
That's exactly one of the places were a cast shouldn't be
used. 'the_word' points to memory you are not allowed to
change. And to get around this you need the cast. So you're
now operating directly on the memory where your word is
stored which could reside in read-only memory.
> for (i=len-1 ; i>=0 ; i--) {
> *pb = buffer[i];
> pb++;
> }
> *pb = '\0';
>> return the_word;
> }
> };
Here's some way you could do it (but note, I didn't carefully
check everything):
------- word.hpp -----------------------------
#ifndef WORD_HPP_
#define WORD_HPP_
#include <cstring>
class Word {
public:
Word( const char * w );
~Word( );
const char * reverse( );
private:
char * the_word;
};
#endif
------- word.cpp -----------------------------
#include "word.hpp"
Word::Word( const char * w )
{
the_word = new char [ ( w != 0 ? strlen( w ) : 0 ) + 1 ];
if ( w != 0 )
strcpy( the_word, w );
else
*the_word = '\0';
}
Word::~Word( )
{
delete [ ] the_word;
}
const char *
Word::reverse( )
{
char *ps = the_word,
*pe = the_word + strlen( the_word );
while ( ps < pe )
{
char tmp = *ps;
*ps++ = *pe;
*pe-- = tmp;
}
return the_word;
}
----------------------------------------------
But since you write C++ it is probably nuch more reasonable
(and safer) to use the std::string class instead of creating
a probably inferior and slower version on your own;-) And all
this is very C-ish, for example in C++ you would rather return
a Word instance from the reverse() method instead of a pointer
to something in the innards of the class...
Regards, Jens
--
\ Jens Thoms Toerring ________ jt at toerring.de
\_______________________________ http://toerring.de
More information about the PyQt
mailing list
‘She has never mentioned her father to me. Was he—well, the sort of man whom the County Club would not have blackballed?’ "We walked by the side of our teams or behind the wagons, we slept on the ground at night, we did our own cooking, we washed our knives by sticking them into the ground rapidly a few times, and we washed our plates with sand and wisps of grass. When we stopped, we arranged our wagons in a circle, and thus formed a 'corral,' or yard, where we drove our oxen to yoke them up. And the corral was often very useful as a fort, or camp, for defending ourselves against the Indians. Do you see that little hollow down there?" he asked, pointing to a depression in the ground a short distance to the right of the train. "Well, in that hollow our wagon-train was kept three days and nights by the Indians. Three days and nights they stayed around, and made several attacks. Two of our men were killed and three were wounded by their arrows, and others had narrow escapes. One arrow hit me on the throat, but I was saved by the knot of my neckerchief, and the point only tore the skin a little. Since that time I have always had a fondness for large neckties. I don't know how many of the Indians we killed, as they carried off their dead and wounded, to save them from being scalped. Next to getting the scalps of their enemies, the most important thing with the Indians is to save their own. We had several fights during our journey, but that one was the worst. Once a little party of us were surrounded in a small 'wallow,' and had a tough time to defend ourselves successfully. Luckily for us, the Indians had no fire-arms then, and their bows and arrows were no match for our rifles. Nowadays they are well armed, but there are[Pg 41] not so many of them, and they are not inclined to trouble the railway trains. They used to do a great deal of mischief in the old times, and many a poor fellow has been killed by them." As dusk came on nearly the whole population of Maastricht, with all their temporary guests, formed an endless procession and went to invoke God's mercy by the Virgin Mary's intercession. They went to Our Lady's Church, in which stands the miraculous statue of Sancta Maria Stella Maris. The procession filled all the principal streets and squares of the town. I took my stand at the corner of the Vrijthof, where all marched past me, men, women, and children, all praying aloud, with loud voices beseeching: "Our Lady, Star of the Sea, pray for us ... pray for us ... pray for us ...!" It had not occurred to her for some hours after Mrs. Campbell had told her of Landor's death that she was free now to give herself to Cairness. She had gasped, indeed, when she did remember it, and had put the thought away, angrily and self-reproachfully. But it returned now, and she felt that she might cling to it. She had been grateful, and she had been faithful, too.[Pg 286] She remembered only that Landor had been kind to her, and forgot that for the last two years she had borne with much harsh coldness, and with a sort of contempt which she felt in her unanalyzing mind to have been entirely unmerited. Gradually she raised herself until she sat quite erect by the side of the mound, the old exultation of her half-wild girlhood shining in her face as she planned the future, which only a few minutes before had seemed so hopeless. After he had gloated over Sergeant Ramsey, Shorty got his men into the road ready to start. Si placed himself in front of the squad and deliberately loaded his musket in their sight. Shorty took his place in the rear, and gave out: The groups about each gun thinned out, as the shrieking fragments of shell mowed down man after man, but the rapidity of the fire did not slacken in the least. One of the Lieutenants turned and motioned with his saber to the riders seated on their horses in the line of limbers under the cover of the slope. One rider sprang from each team and ran up to take the place of men who had fallen. "As long as there's men and women in the world, the men 'ull be top and the women bottom." Then, in the house, the little girls were useful. Mrs. Backfield was not so energetic as she used to be. She had never been a robust woman, and though her husband's care had kept her well and strong, her frame was not equal to Reuben's demands; after fourteen years' hard labour, she suffered from rheumatism, which though seldom acute, was inclined to make her stiff and slow. It was here that Caro and Tilly came in, and Reuben began to appreciate his girls. After all, girls were needed in a house—and as for young men and marriage, their father could easily see that such follies did not spoil their usefulness or take them from him. Caro and Tilly helped their grandmother in all sorts of ways—they dusted, they watched pots, they shelled peas and peeled potatoes, they darned house-linen, they could even make a bed between them. HoME一级毛片视频免费公开
ENTER NUMBET 0018ssigroup.com.cn www.sorci-age.com.cn www.laijianshen.com.cn www.ertrtdf.com.cn www.hefae.com.cn fmvh.com.cn amzinck.com.cn cyjh.net.cn hb-cx.com.cn www.mzvl.com.cn