Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > passing parameter

Reply
Thread Tools

passing parameter

 
 
Eric Kaplan
Guest
Posts: n/a
 
      04-04-2008
why calling PostSoapRequest will crash the program?

should I pass string* for start and end?


int post_soap_request(string start, string end)
{
string request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ start + end;
const char* REQUEST_BODY = request.c_str();

ne_set_request_body_buffer(req, REQUEST_BODY,
strlen(REQUEST_BODY));

// some more code

return 0;
}

HRESULT PostSoapRequest(string start, string end) {
return (post_soap_request(start, end) == 0) ? S_OK : E_FAIL;
}
 
Reply With Quote
 
 
 
 
Sharad
Guest
Posts: n/a
 
      04-04-2008

"Eric Kaplan" <(E-Mail Removed)> wrote in message

> why calling PostSoapRequest will crash the program?
>
> should I pass string* for start and end?


Why? What's the intention of your program?

>
> int post_soap_request(string start, string end)
> {
> string request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
> + start + end;
> const char* REQUEST_BODY = request.c_str();
>
> ne_set_request_body_buffer(req, REQUEST_BODY,
> strlen(REQUEST_BODY));


Where is the definition of this function? What is req?

> // some more code
>
> return 0;
> }
>
> HRESULT PostSoapRequest(string start, string end) {
> return (post_soap_request(start, end) == 0) ? S_OK : E_FAIL;
> }



Some tips
- Post the minimal code that compiles and demonstrates the crash. People
here can then help you better.
- Use debugger provided for your platform (seems like Windows to me)

Sharad


 
Reply With Quote
 
 
 
 
Eric Kaplan
Guest
Posts: n/a
 
      04-04-2008
the problem is parameter using "string start" instead of

int post_soap_request(string const& start, string const& end)

but i am not very sure the difference

string start / string const& start


>Some tips
>- Post the minimal code that compiles and demonstrates the crash. People
>here can then help you better.
>- Use debugger provided for your platform (seems like Windows to me)
>
>Sharad
>

 
Reply With Quote
 
Sharad
Guest
Posts: n/a
 
      04-04-2008

"Eric Kaplan" <(E-Mail Removed)> wrote in message
> the problem is parameter using "string start" instead of
>
> int post_soap_request(string const& start, string const& end)
>
> but i am not very sure the difference
>
> string start / string const& start


They mean pass by value, and pass by reference respectively. For user
defined types generally the latter form is preferred.
Through pass by value the caller does not get affected by the changes made
inside the function to the variable. The last statement does not hold true
for pass by reference.

Sharad




 
Reply With Quote
 
Michael Oswald
Guest
Posts: n/a
 
      04-04-2008
Eric Kaplan wrote:

> int post_soap_request(string start, string end)
> {
> string request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
> + start + end;


I would say, this line, followed by the others is the problem:

> const char* REQUEST_BODY = request.c_str();
>
> ne_set_request_body_buffer(req, REQUEST_BODY,
> strlen(REQUEST_BODY));


You take a pointer to a temporary. This is undefined behaviour.

Try this:

ne_set_request_body_buffer(req, request.c_str(),
request.size());

and remove the cont char*.

hth,
Michael

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing parameter to function not expecting parameter Mister B C Programming 8 08-26-2010 08:01 AM
decltype as a template parameter when containing reference to anothertemplate parameter. Isti C++ 2 04-19-2010 10:01 PM
without declare parameter [double square(parameter)] return 0 in main WanHongbin@gmail.com C Programming 5 10-01-2008 03:31 AM
Using declaration inside first template parameter as default valuefor second template parameter. Stuart Redmann C++ 5 12-14-2007 08:42 AM
Parameter List / Parameter Block / Anything patterns... mast2as@yahoo.com C++ 4 03-29-2007 09:37 PM



Advertisments