Ok, back to basics here.
I was completly shocked and dismayed today when one of my apps returned an
error from main. Not so much that it returned an error, that was expected.
But what happened.
I swear that main was supposed to return "int", i.e. some postive/neg
integer of unknown byte lenght(compiler/platform depenendent byte lenght of
course)
So anyways.
I just found out, that on my current system. RedHat ES 3, the return status
from the shell is only an 8 byte unsigned integer. I swear I had more range
before, but that was under different shells and OS's.
So. Is this a OS, shell, or compiler limit?
Meaning, I want to code the correct thing, I just don't know now how to
validly code it, as I had thought main in C/C++ was always supposed to
return (int)
I'm switching my return codes to postive 0-255 value now. Not so bad as the
couple peices of software that interact with this I also now maintain. But
just would like more on this story.
-grant 3 4522
* Grant Schoep: Ok, back to basics here.
I was completly shocked and dismayed today when one of my apps returned an error from main. Not so much that it returned an error, that was expected. But what happened.
I swear that main was supposed to return "int", i.e. some postive/neg integer of unknown byte lenght(compiler/platform depenendent byte lenght of course)
So anyways.
I just found out, that on my current system. RedHat ES 3, the return status from the shell is only an 8 byte unsigned integer.
You mean 8 bits.
I swear I had more range before, but that was under different shells and OS's.
So. Is this a OS, shell, or compiler limit?
Yes.
Meaning, I want to code the correct thing, I just don't know now how to validly code it, as I had thought main in C/C++ was always supposed to return (int)
The language defines only three values: 0, EXIT_SUCCESS, and EXIT_FAILURE,
where 0 and EXIT_SUCCESS have the same conceptual meaning, namely success,
and EXIT_SUCCESS is most probably but not necessarily defined as 0.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Grant Schoep wrote: Ok, back to basics here.
I was completly shocked and dismayed today when one of my apps returned an error from main. Not so much that it returned an error, that was expected. But what happened.
I swear that main was supposed to return "int", i.e. some postive/neg integer of unknown byte lenght(compiler/platform depenendent byte lenght of course)
So anyways.
I just found out, that on my current system. RedHat ES 3, the return status from the shell is only an 8 byte unsigned integer. I swear I had more range before, but that was under different shells and OS's.
So. Is this a OS, shell, or compiler limit?
Maybe.
Meaning, I want to code the correct thing, I just don't know now how to validly code it, as I had thought main in C/C++ was always supposed to return (int)
In Standard C++, the three values EXIT_FAILURE, EXIST_SUCCESS (from
<cstdlib>) and 0 are the only valid values that main can return. Most
platforms support more values - which is useful to indicate the type of
error - but the details are of course platform specific.
> I'm switching my return codes to postive 0-255 value now. Not so bad as the couple peices of software that interact with this I also now maintain. But just would like more on this story.
Check this: http://gnu.rtin.bz/prep/standards_13.html This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: cppaddict |
last post by:
I'd like to know what goes on under the hood when methods return
objects. Eg, I have a simple Point class with two members _x and _y.
It's constructor, copy constructor, assignment operator and additon
operator (which returns another Point object, and which my question is
about) are as follows:
Point::Point(int x, int y) :
_x(x),
_y(y) { }
|
by: Mike Machuidel |
last post by:
Hi,
I'm a game developer programming mostly in C and ASM for about 7 years.
Today at work a colleague (a C++ programmer) yelled at me I'm a bad C
programmer because I use "return(0);" instead of "return 0;".
He explained that "return" is not a function but a stament, like I
didn't know already. The other colleagues also argreed with him :(.
Can someone please explain what's so wrong about using "return" with
|
by: M. Moennigmann |
last post by:
Dear all:
I would like to write a function that opens a file, reads and stores
data into an 2d array, and passes that array back to the caller
(=main). The size of the array is not known before opening to the
file.
I fail to write a function that allocates memory for a 2d array and
returns it to main. I was trying to pass a pointer to the array back
to main, but main cannot access the data. The simplified code (no
opening of file, but...
|
by: G Patel |
last post by:
Hi,
If I want to call functions that don't return int without declaring
them, will there be any harm?
I only want to assign the function(return value) to the type that it
returns, so I don't see how the return value comes to play here.
Ex
|
by: jwaixs |
last post by:
Hello,
I was wondering, what's the difference between exit and return in the
main() function? For me they both look the same, or aren't they? And if
they aren't, which should I use in which situation?
Also I was wondering if it whould be wise to combine the standard
status with return.
exp:
| |
by: lovecreatesbeauty |
last post by:
Hello experts,
Is the following code snippet legal? If it is, how can exit() do the
keyword return a favor and give a return value to the main function?
Can a function call (or only this exit(n)) statement provide both
function call and return features of the C programming language?
/* headers omitted */
int main (void)
|
by: Christian Christmann |
last post by:
Hi,
the ANSI-C 99 standard specifies that the main function
has "int" as return type. However, there are still lots
of people declaring "void" as main return type.
Did previous ANSI-C standards defined "void" as return type
or is this issue just a lack of C knowledge?
Regards,
|
by: junky_fellow |
last post by:
Guys,
Can I return 0, from main() ? Is this equivalent to
exit(EXIT_SUCCESS) ?
thanks for any help...
|
by: Bill Cunningham |
last post by:
I have heard that return -1 is not portable. So what would be the answer
to portability in this case? What about exit(0) and exit (-1) or exit (1)?
Or would it be best to stick with C's macros, hence:
exit(EXIT_FAILURE)
exit (EXIT_SUCCESS)
Bill
|
by: Rahul |
last post by:
Hi Everyone,
I have seen code in different styles like
main(argc,argv)
int argc;
char **argv;
{
if(argc != 2) exit(1);
else exit(0);
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |