converting an xml c++ parser to be c

Started by
7 comments, last by Nytegard 16 years, 10 months ago
Hi there guys just wondered if anyone could give me a hand at converting this c++ xml parser to be c [Edited by - Prog101 on June 9, 2007 10:25:16 AM]
Advertisement
Help Wanted forum or rentacoder.com or some similar site would be where to look for help.

People here will only help you if you do it yourself, but run into problems.

But posting several kLOC of code and asking for someone to convert it is somewhat unrealistic.

Especially since fully standard-compliant validating XML parsers written in C are abundant on google.

The code is pretty well written, it doesn't contain too many high-level concepts, so as soon as you remove classes, you should have a pretty decent solution.

General advice:
// C++class X {  void foo( int x, int y );  int m_local;}// in Ctypedef struct XClass {  int m_local;} X;int X_foo( X *x, int x, int y);


This should take care of classes.
yeah i mean the only real class it has is

class DLLENTRY ToXMLStringTool{public:    ToXMLStringTool(): buf(NULL),buflen(0){}    ~ToXMLStringTool();    void freeBuffer();    XMLSTR toXML(XMLCSTR source);private:    XMLSTR buf;    int buflen;};


so how would you convert that with the constructor/destuctor
Quote:Original post by Prog101
yeah i mean the onnly real class it has is

*** Source Snippet Removed ***

so how would you convert that with the constructor/destuctor


In what way are constructor and destructor different from regular methods?

Don't mind the syntax, look at the function they perform.

Constructor:
- Allocates the structure that holds class data
- Initializes some of the local variables
- Optionally performs some other, user define processing in body, same as any other method
Is this considered C or C++:

struct DataSet
{
DataSet();
~DataSet();

int* data;
};
i have looked all over for a good c xml parser to use with a license that does not resrict me using it for a published game, if you know of any c xml parser would you post the .h and .c files on here?
Quote:Original post by Prog101
i have looked all over for a good c xml parser to use with a license that does not resrict me using it for a published game, if you know of any c xml parser would you post the .h and .c files on here?


http://www.saunalahti.fi/~samiuus/toni/xmlproc/

Just the first suitable link from google. Should be more.

Quote:Original post by Endemoniada
Is this considered C or C++:

struct DataSet
{
DataSet();
~DataSet();

int* data;
};


That is C++. Structs cannot have member functions, constructors, or destructors in C.
Quote:Original post by Prog101
yeah i mean the only real class it has is


so how would you convert that with the constructor/destuctor


Simply move the functions to their own file for simplicity reasons, and have

struct myStruct{  XMLSTR buf;  int buflen;}MYSTRUCT;


The first parameter of the class should be of void foo(struct myStruct *bar,...

The constructor and destructor act just like normal functions, but you'll have to remember to call them appropriately. There are ways around this of course, and it is possible to make C more object oriented, but that's a little more complicated.

This topic is closed to new replies.

Advertisement