473,385 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Is it possible to finding all return values of a C/C++ function?

Hello everyone,

I'm updating some documents that describes so many C/C++
functions/method(about 2500).
But I'm not familiar with these codes. So I want to find such a utility
can generate returning value list from the codes.
Is it possible? Or is it hard to write one?

Thanks.

Aug 8 '06 #1
17 1996
bi********@gmail.com (in
11**********************@75g2000cwc.googlegroups.c om) said:

| I'm updating some documents that describes so many C/C++
| functions/method(about 2500).
| But I'm not familiar with these codes. So I want to find such a
| utility can generate returning value list from the codes.
| Is it possible? Or is it hard to write one?

Consider just one possible function:

double binjobster_div(double a, double b)
{ return a/b;
}

I think I'll let you answer your own question. :-)

--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto
Aug 8 '06 #2
I'm sorry I forgot to mention that all the code here returns the same
type. Let's say it's a predefined enumeration. So we won't get float or
double.

Morris Dovey wrote:
bi********@gmail.com (in
11**********************@75g2000cwc.googlegroups.c om) said:

| I'm updating some documents that describes so many C/C++
| functions/method(about 2500).
| But I'm not familiar with these codes. So I want to find such a
| utility can generate returning value list from the codes.
| Is it possible? Or is it hard to write one?

Consider just one possible function:

double binjobster_div(double a, double b)
{ return a/b;
}

I think I'll let you answer your own question. :-)

--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto
Aug 8 '06 #3
bi********@gmail.com wrote:

Please don't top-post or quote signatures, corrected.
Morris Dovey wrote:
>>bi********@gmail.com (in
11**********************@75g2000cwc.googlegroups .com) said:

| I'm updating some documents that describes so many C/C++
| functions/method(about 2500).
| But I'm not familiar with these codes. So I want to find such a
| utility can generate returning value list from the codes.
| Is it possible? Or is it hard to write one?

Consider just one possible function:

double binjobster_div(double a, double b)
{ return a/b;
}

I think I'll let you answer your own question. :-)
I'm sorry I forgot to mention that all the code here returns the same
type. Let's say it's a predefined enumeration. So we won't get float or
double.
So what do you want to find? Are you trying to predict what the
functions return?

--
Ian Collins.
Aug 8 '06 #4

Ian Collins wrote:
bi********@gmail.com wrote:

Please don't top-post or quote signatures, corrected.
Morris Dovey wrote:
>bi********@gmail.com (in
11**********************@75g2000cwc.googlegroups. com) said:

| I'm updating some documents that describes so many C/C++
| functions/method(about 2500).
| But I'm not familiar with these codes. So I want to find such a
| utility can generate returning value list from the codes.
| Is it possible? Or is it hard to write one?

Consider just one possible function:

double binjobster_div(double a, double b)
{ return a/b;
}

I think I'll let you answer your own question. :-)
I'm sorry I forgot to mention that all the code here returns the same
type. Let's say it's a predefined enumeration. So we won't get float or
double.
So what do you want to find? Are you trying to predict what the
functions return?

--
Ian Collins.
I'm sorry I'm a newbie on news group.

Functions may call another function like below:

RTCODE foo1(TYPE1 a1, TYPE2 a2)
{
if (cond1)
return foo2(...);
else if (cond2)
return foo3(...);
return ERROR_NONE;
}

RTCODE foo2(TYPE1 a1, TYPE2 a2)
{
....
return ERROR_OUT_OF_MEMORY;
}

And reading code to list all the return values of foo1() is time
consuming, so I ask for a utility can do the job automatically.

Aug 8 '06 #5
<bi********@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
I'm sorry I forgot to mention that all the code here returns the same
type. Let's say it's a predefined enumeration. So we won't get float or
double.
long long binjobster_div(long long a, long long b)
{ return a/b;
}

There are 3.4e+38 different inputs and 18446744073709551616 different
outputs (unless long long is bigger than 64 bits, in which case it is more).

I guess that you are not patient to enumerate them all, especially since
18446744073709551616 or so combinations result in a trap representation.

I doubt if anyone has the patience or lifespan to complete the task. We
could use the internet, but I doubt if the answer to the question is worth
the bother, since a moment's thought will show us what the answers can be.

In addition, on some machines, int is 64 bits.

I generally try to exhaustively test functions. But when the total bytes of
input (after dereferencing pointers) exceeds 4, I generally switch to
probability based approaches ( along with endpoint tests and other extreme
conditions ).
Aug 8 '06 #6
bi********@gmail.com wrote:
>
I'm sorry I'm a newbie on news group.

Functions may call another function like below:

RTCODE foo1(TYPE1 a1, TYPE2 a2)
{
if (cond1)
return foo2(...);
else if (cond2)
return foo3(...);
return ERROR_NONE;
}

RTCODE foo2(TYPE1 a1, TYPE2 a2)
{
....
return ERROR_OUT_OF_MEMORY;
}

And reading code to list all the return values of foo1() is time
consuming, so I ask for a utility can do the job automatically.
You won't find one. Just look at your first example, if foo2 or foo3
call other functions, you will very quickly get an exponential growth in
the number of possible returns for any function, or at best any valid
value of RTCODE.

Sounds like a pointless exercise to me.

--
Ian Collins.
Aug 8 '06 #7

bi********@gmail.com wrote:
Hello everyone,

I'm updating some documents that describes so many C/C++
functions/method(about 2500).
But I'm not familiar with these codes. So I want to find such a utility
can generate returning value list from the codes.
Is it possible? Or is it hard to write one?

Thanks.
If I read you right (in this and your followup posts), all the relevant
functions return predetermined constants from a relatively small pool
of such (ruling out the division function someone else keeps
mentioning). If you are content with simply assuming that if a
function contains the line "return CONSTANT_BLAH" that it is somehow
possible for that function to indeed return CONSTANT_BLAH, then it
wouldn't be overwhelmingly difficult to just program your own simple
program to read in your .c files and parse them. When I say "it
wouldn't be overwhelmingly difficult" though, the emphasis is on
"overwhelmingly", this would probably be a week's worth of work if
you're new to file I/O and/or parsing text. (Well... this is assuming
you can assume the code is pretty well-behaved... if you wanted it to
be guaranteed to work no matter how scandalous the code in question,
then you'd practically have to include an entire preprocessor...)

On the other hand, if you want the program to be intelligent enough to
only count return lines which are actually reachable, then a general
solution would not be Turing computable since it would allow halting
oracles to be created...

S.P.

Aug 8 '06 #8
First suggestion:
Read the project's documentation to find the answers. If that is missing,
go polaxe the project's originator, until he provides the needed
information.

Second suggestion:
If he cannot be located for a good polaxing, then I suggest grepping through
the headers to find the enums and/or #defines that you are searching for and
building your case statements from those.

Third suggestion:
If the headers are missing and the documenation is missing, then it is
better to write a new solution from scratch (no, I'm not kidding).
Aug 8 '06 #9
bi********@gmail.com (in
11**********************@m73g2000cwd.googlegroups. com) said:

|
| Morris Dovey wrote:
|| bi********@gmail.com (in
|| 11**********************@75g2000cwc.googlegroups.c om) said:
||
||| I'm updating some documents that describes so many C/C++
||| functions/method(about 2500).
||| But I'm not familiar with these codes. So I want to find such a
||| utility can generate returning value list from the codes.
||| Is it possible? Or is it hard to write one?
||
|| Consider just one possible function:
||
|| double binjobster_div(double a, double b)
|| { return a/b;
|| }
||
|| I think I'll let you answer your own question. :-)

| I'm sorry I forgot to mention that all the code here returns the
| same type. Let's say it's a predefined enumeration. So we won't get
| float or double.

Ok. My trivial example does provide a clue that a utility providing a
general solution isn't practical. If only enumerated values are
returned, then it should be sufficient to examine the sources to
determine which of the enumerated values are actually returned.

That certainly should be possible. Whether or not the utility you want
is hard to write depends on your own talents and skills...

--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto
Aug 8 '06 #10
Snis Pilbor wrote:
If I read you right (in this and your followup posts), all the relevant
functions return predetermined constants from a relatively small pool
of such (ruling out the division function someone else keeps
mentioning). If you are content with simply assuming that if a
function contains the line "return CONSTANT_BLAH" that it is somehow
possible for that function to indeed return CONSTANT_BLAH, then it
wouldn't be overwhelmingly difficult to just program your own simple
program to read in your .c files and parse them. When I say "it
wouldn't be overwhelmingly difficult" though, the emphasis is on
"overwhelmingly", this would probably be a week's worth of work if
you're new to file I/O and/or parsing text. (Well... this is assuming
you can assume the code is pretty well-behaved... if you wanted it to
be guaranteed to work no matter how scandalous the code in question,
then you'd practically have to include an entire preprocessor...)

On the other hand, if you want the program to be intelligent enough to
only count return lines which are actually reachable, then a general
solution would not be Turing computable since it would allow halting
oracles to be created...

S.P.
Is there any similiar implementations or examples on the problem?

It need some parsing work. I have some experience on stdio and regexp
but don't on such software tools like YACC or bison.

Aug 8 '06 #11
<bi********@gmail.comwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...
I'm sorry I'm a newbie on news group.

Functions may call another function like below:

RTCODE foo1(TYPE1 a1, TYPE2 a2)
{
if (cond1)
return foo2(...);
else if (cond2)
return foo3(...);
return ERROR_NONE;
}

RTCODE foo2(TYPE1 a1, TYPE2 a2)
{
....
return ERROR_OUT_OF_MEMORY;
}

And reading code to list all the return values of foo1() is time
consuming,
That's why code should be documented. The comments for foo2() and
foo3() should clearly state all possible return values; the comments
for foo1() should either enumerate all of those return values plus
ERROR_NONE, or they should say something like "returns ERROR_NONE or
the result of foo2() or foo3()" so that readers know to read through
those functions' comments as well.

In the absence of such documentation, you _must_ assume that foo1()
can return any possible value of type RTCODE (whatever that is). And,
in practice, it's generally a good idea to handle all possible values
even if the comments indicate they shouldn't happen, at least in debug
builds, so that you can handle errors in the comments.
so I ask for a utility can do the job automatically.
Since a utility can't read documentation, you won't get a satisfactory
answer. Fix the documentation and you won't need a utility anyways.

S

--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking

--
Posted via a free Usenet account from http://www.teranews.com

Aug 8 '06 #12
>I'm updating some documents that describes so many C/C++
>functions/method(about 2500).
But I'm not familiar with these codes. So I want to find such a utility
can generate returning value list from the codes.
Is it possible? Or is it hard to write one?
If the function returns int, and it is written portably, then there are
no more than 65,536 different return values from that function.
(Although int can be larger than 16 bits and often is, portable C can't assume
that.)

If you've got a header file containing a bunch of definitions of error
codes, e.g.:

#define FAIL_LIPSTICK_AT_AIRPORT_SECURITY_GATE 7620

you could try counting the lines in the file.

I suspect determining all the possible return values from a function
is equivalent to the halting problem.

Aug 10 '06 #13
Gordon Burditt posted:
If the function returns int, and it is written portably, then there are
no more than 65,536 different return values from that function.
Correction: no more than 65 535 different return values.

Minimum range: -32 767 through 32 767

That's 65 535 unique values.

--

Frederick Gotham
Aug 10 '06 #14
go***********@burditt.org (Gordon Burditt) wrote:
If you've got a header file containing a bunch of definitions of error
codes, e.g.:

#define FAIL_LIPSTICK_AT_AIRPORT_SECURITY_GATE 7620
YM

#define FAIL_WATER_BOTTLE_AT_AIRPORT_SECURITY_GATE 7620
#define FAIL_NECESSARY_MEDICINE_AT_AIRPORT_SECURITY_GATE 7621

Argh and cthulhudamn. I _was_ going to fly to London tomorrow and add
some money to the British economy. I'm having serious doubts now.

Richard
Aug 11 '06 #15
Gordon Burditt wrote:

<snip>
I suspect determining all the possible return values from a function
is equivalent to the halting problem.
Part of the problem of all possible return values is the halting
problem. Since one thing you have to determine is whether the function
will halt (i.e. return). If it never returns the number of possible
return values is 0.
--
Flash Gordon
Still sigless on this computer.
Aug 11 '06 #16
Frederick Gotham wrote:
Gordon Burditt posted:

>>If the function returns int, and it is written portably, then there are
no more than 65,536 different return values from that function.


Correction: no more than 65 535 different return values.

Minimum range: -32 767 through 32 767
Correction: -32 768 through 32 767

For unsigned: 0 through 65 535
That's 65 535 unique values.
That's 65 536 values.

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Aug 25 '06 #17
Kevin Handy posted:
Frederick Gotham wrote:
>>>If the function returns int, and it is written portably, then there are
no more than 65,536 different return values from that function.
>Correction: no more than 65 535 different return values.

Minimum range: -32 767 through 32 767
Correction: -32 768 through 32 767

Incorrect. The minimum range of an "int" is:

-32767 through 32767

It may so happen that on a system where int's are 32-Bit and are two's
complement, that the range is -32768 through 32767, but this cannot be
relied upon in portable code.

For unsigned: 0 through 65 535
>That's 65 535 unique values.

That's 65 536 values.

Yes, you're correct.

--

Frederick Gotham
Aug 25 '06 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: B Moor | last post by:
I have a database with 100,000's records, each with a unique reference, eg A123BNK456 I would like to generate a search facility whereby we can choose an exact match or partial match, where the...
18
by: skishorev | last post by:
Hi, Here I am taking two functions. void f(int,int) and another one is float f(int,int). Is it possible to overload with return values. Thx, kishore
13
by: Alison Givens | last post by:
....... that nobody knows the answer. I can't imagine that I am the only one that uses parameters in CR. So, my question again: I have the following problem. (VB.NET 2003 with CR) I have a...
2
by: lcaamano | last post by:
We have a tracing decorator that automatically logs enter/exits to/from functions and methods and it also figures out by itself the function call arguments values and the class or module the...
2
by: Extremest | last post by:
Here is the code I have so far. It connects to a db and grabs headers. It then sorts them into groups and then puts all the complete ones into another table. Problem I am having is that for some...
28
by: beach.dk | last post by:
Hi, I'm trying to implement a simple hash algorith called rs_hash in javascript, but I cannot get a correct result. In c the code looks like this:
3
nomad
by: nomad | last post by:
When I run choice == 2 I'm suppose to a an out.println back finding a product. but I get Null for all the values. Can someone help me with this. class Computer_listing { private String id; ...
12
by: Jeff | last post by:
As I'm learning PHP, I'm making a fair number of mistakes in syntax. In perl, you can turn on reading these errors from the browser by adding this: use CGI::Carp 'fatalsToBrowser'; Is there...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.