return-value

Why does int main() {} compile?

(I'm using Visual C++ 2008) I've always heard that main() is required to return an integer, but here I didn't put in return 0; and and it compiled with 0 errors and 0 warnings! In the debug window it says the program has exited with code 0. If this function is named anything other than main(), the compiler complains saying 'blah' must ...

How can I return a variable from a $.getJSON function

I want to return StudentId to use elsewhere outside of the scope of the $.getJSON() j.getJSON(url, data, function(result) { var studentId = result.Something; }); //use studentId here I would imagine this has to do with scoping, but it doesn't seem to work the same way c# does ...

Which syntax is better for return value?

I've been doing a massive code review and one pattern I notice all over the place is this: public bool MethodName() { bool returnValue = false; if (expression) { // do something returnValue = MethodCall(); } else { // do something else returnValue = Expression; } return re...

How to indicate that a method was unsuccessful

I have several similar methods, say eg. CalculatePoint(...) and CalculateListOfPoints(...). Occasionally, they may not succeed, and need to indicate this to the caller. For CalculateListOfPoints, which returns a generic List, I could return an empty list and require the caller to check this; however Point is a value type and so I can't r...

What is returned from a function that returns the return of another function in C++?

If I want to call Bar() instead of Foo(), does Bar() return me a copy (additional overhead) of what Foo() returns, or it returns the same object which Foo() places on the temporary stack? vector<int> Foo(){ vector<int> result; result.push_back(1); return result; } vector<int> Bar(){ return Foo(); } ...

"TryParse / Parse like" pattern: what is the best way to implement it

This question is a follow-up from How to indicate that a method was unsuccessful. The xxx() Tryxxx() pattern is something that can be very useful in many libraries. I am wondering what is the best way to offer both implementations without duplicating my code. What is best: public int DoSomething(string a) { // might throw an excep...

Caching a const char * as a return type

Hi all.. Was reading up a bit on my C++, and found this article about RTTI (Runtime Type Identification): http://msdn.microsoft.com/en-us/library/70ky2y6k(VS.80).aspx . Well, that's another subject :) - However, I stumbled upon a weird saying in the type_info-class, namely about the ::name-method. It says: "The type_info::name member fu...

Can I find out the return value before returning while debugging in Eclipse

Is it possible to see the return value of a method after the line has been run and before the instruction pointer returns to the calling function? I am debugging code I can't modify (read: don't want to re-compile a third party library), and sometimes it jumps to code I don't have source to or the return expression has side effects that...

Best Practice: function return value or byref output parameters?

I have a function called FindSpecificRowValue that takes in a datatable and returns the row number that contains a particular value. If that value isn't found, I want to indicate so to the calling function. Is the best approach to: Write a function that returns false if not found, true if found, and the found row number as a byref/out...

Should return values and arguments for public methods only be types from within the same assembly?

I am wondering what are the best practices for public methods and their return values. Is it ok to return types from referenced assemblies or should I make sure that all the parameters as well as return values are all from within the same assembly? The reason I ask is that I am in the process of merging assemblies with ILMerge and I wo...

Inspect the return value of a function in gdb

Is it possible to inspect the return value of a function in gdb assuming the return value is not assigned to a variable? ...

Scope and return values in C++

Hey!! I am starting again with c++ and was thinking about the scope of variables. If I have a variable inside a function and then I return that variable will the variable not be "dead" when it's returned because the scope it was in has ended? I have tried this with a function returning a string and it did work. Can anyone explain this?...

What happens if you don't return a value in C++?

Yesterday, I found myself writing code like this: SomeStruct getSomeStruct() { SomeStruct input; cin >> input.x; cin >> input.y; } Of course forgetting to actually return the struct I just created. Oddly enough, the values in the struct that was returned by this function got initialized to zero (when compiled using g++ t...

Can you hint return types in PHP 5.2.5?

I think my eclipse's ctrl+clicking links might benefit greatly... Edit: I'm using eclipse PDT. Edit 2: I'm very happy with the solution of putting docblocks before functions (and variables) with an @return or @var statement, I've just updated the documentation of my app and now eclipse is showing me what functions are available to what...

Best way to return status flag and message from a method in Java

I have a deceptively simple scenario, and I want a simple solution, but it's not obvious which is "most correct" or "most Java". Let's say I have a small authenticate(Client client) method in some class. The authentication could fail for a number of reasons, and I want to return a simple boolean for control flow, but also return a Strin...

What values to return for S_OK or E_FAIL from c# .net code?

I'm implementing a COM interface that should return int values either S_OK or E_FAIL. I'm ok returning S_OK as I get that back from another call (Marshal.QueryInterface), but if I want to return a failure value what actual value do I use for E_FAIL? (It's such a basic fundamental question that it's hard to find an answer to) Assuming i...

Retrieve return value from DB2 stored procedure

I have a block of code that is repeated within a DB2 stored procedure. I would like to separate this out into a new procedure that I can call with parameters and have it return a value. How do I create a procedure to return a value and how do I call this procedure from inside my original procedure? ...

mySQL stored procedure where clause problem

Hi! I've got a mySql stored procedure that looks like this-- delimiter | create procedure GetEmployeeById(in ID varchar(45)) begin select id, firstName, lastName, phone, address1, address2, city, state, zip, username, password, emptypeid from myschema.tblemployees t ...

JQuery Ajax Return value

Dear all, I have jquery that, i have called an ajax function file.php , that has some fields like Milk , Will I assign into again JQuery function, If so how to do It?.I attached the sample file <html> <head> <LINK REL=StyleSheet HREF="examples.css" TITLE="Contemporary" TYPE="text/css"> <script src="jquery-1.2.6.js" type="text/j...

Using return statements to great effect!

When I am making methods with return values, I usually try and set things up so that there is never a case when the method is called in such a way that it would have to return some default value. When I started I would often write methods that did something, and would either return what they did or, if they failed to do anything, would r...