473,837 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Function arguments

Hi,
I wanted to know when we call function with argument, Does the
arguments stored in stack always or it compiler specific and could be
stored in queue

e.g. Does this program's output depends upon the compiler specific or
always would be b a

#include<stdio. h>

int a()
{
printf("a\t");
return 0;
}
int b()
{
printf("b\t");
return 0;
}
void c(int a,int b)
{
}
int main()
{
c(a(),b());
return 1;
}
Thanks,
Amit
Nov 14 '05 #1
7 3315
Amit Sharma wrote:
Hi,
I wanted to know when we call function with argument, Does the
arguments stored in stack always or it compiler specific and could be
stored in queue
They can be stored however the implementor likes. A common choice, on
machines where it's available, is to store at least the first few
arguments in registers.
c(a(),b());


The arguments of a function call can be evaluated in whatever order
the compiler (writer) finds convenient and effective.

--
Chris "electric hedgehog" Dollin
C FAQs at: http://www.faqs.org/faqs/by-newsgrou...mp.lang.c.html
C welcome: http://www.angelfire.com/ms3/bchambl...me_to_clc.html
Nov 14 '05 #2
In <fe************ *************@p osting.google.c om> sh*******@gmail .com (Amit Sharma) writes:
I wanted to know when we call function with argument, Does the
arguments stored in stack always or it compiler specific and could be
stored in queue
Why does it matter to you?
e.g. Does this program's output depends upon the compiler specific or
always would be b a

#include<stdio .h>

int a()
{
printf("a\t");
return 0;
}
int b()
{
printf("b\t");
return 0;
}
void c(int a,int b)
{
}
int main()
{
c(a(),b());
return 1;
}


I see no connection between your first question and the second one,
although the second was supposed to exemplify the first.

The output of the program is not affected by how and where the function
arguments are stored, but it is affected by the order in which the
function arguments are evaluated, which is something completely different.
The order of evaluation is unspecified, therefore the program can output
either "a\tb\t" or "b\ta\t". Or nothing at all, because the last line of
output is not newline terminated.

BTW, what is the effect of returning 1 from main?

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Currently looking for a job in the European Union
Nov 14 '05 #3
On 30 Sep 2004 05:56:31 -0700, sh*******@gmail .com (Amit Sharma) wrote:

Hi,
I wanted to know when we call function with argument, Does the
arguments stored in stack always or it compiler specific and could be
stored in queue


Curious. I can't find the word "stack" anywhere in the C standard. So,
"no" would be the answer to the first part of the question.
--
#include <standard.discl aimer>
_
Kevin D Quitt USA 91387-4454 96.37% of all statistics are made up
Per the FCA, this address may not be added to any commercial mail list
Nov 14 '05 #4
The default calling convention for C is _cdecl. It means parameters are
pushed onto the stack in the reversed order (right to left) and the caller
needs to clean up the stack. There are other conventions, for example,
_stdcall is used for Win32 API functions. For your question, it is true when
you use gcc and run it on GNU/Linux systems. Since it's a default
convention, I assume other compliers will give you the same thing unless you
specify it. But again, I could be wrong in the second case.

-Jamie
"Amit Sharma" <sh*******@gmai l.com> wrote in message
news:fe******** *************** **@posting.goog le.com...
Hi,
I wanted to know when we call function with argument, Does the
arguments stored in stack always or it compiler specific and could be
stored in queue

e.g. Does this program's output depends upon the compiler specific or
always would be b a

#include<stdio. h>

int a()
{
printf("a\t");
return 0;
}
int b()
{
printf("b\t");
return 0;
}
void c(int a,int b)
{
}
int main()
{
c(a(),b());
return 1;
}
Thanks,
Amit



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Nov 14 '05 #5
"Jamie Lin" <ja***@tildefoo .com> writes:
The default calling convention for C is _cdecl. It means parameters are
pushed onto the stack in the reversed order (right to left) and the caller
needs to clean up the stack. There are other conventions, for example,
_stdcall is used for Win32 API functions. For your question, it is true when
you use gcc and run it on GNU/Linux systems. Since it's a default
convention, I assume other compliers will give you the same thing unless you
specify it. But again, I could be wrong in the second case.


First, please don't top-post. Your response should follow, not
precede, any text you quote from previous messages. (See other
articles in this newsgroup for examples.)

Second, there is no such thing as "_cdecl" in standard C, nor does C
require the existence of a stack. As far as the standard is
concerned, parameters could be pushed onto the stack in forward,
reverse, or alphabetical order, stored in registers, or sent by
carrier pigeon. What you say may (or may not; I don't know) be valid
for some particular system, but I assure you there are plenty of
systems where it isn't.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #6
Jamie Lin wrote:

The default calling convention for C is _cdecl. It means parameters
are pushed onto the stack in the reversed order (right to left) and
the caller needs to clean up the stack. There are other conventions,
for example, _stdcall is used for Win32 API functions. For your
question, it is true when you use gcc and run it on GNU/Linux
systems. Since it's a default convention, I assume other compliers
will give you the same thing unless you specify it. But again, I
could be wrong in the second case.


Don't toppost. Your answer belongs after, or intermixed with, the
material to which you are replying, after snipping away anything
that is not relevant.

C has no default calling convention. _cdecl and _stdcall are
specific to some systems and are not portable. The parameter
order is not defined, and neither is the existence of a stack.

--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Nov 14 '05 #7
"Jamie Lin" <ja***@tildefoo .com> wrote in message news:<41******* *@corp.newsgrou ps.com>...
The default calling convention for C [edit] on the Win32 platform [/edit] is
_cdecl.
Fixed that for you.
It means parameters are
pushed onto the stack in the reversed order (right to left) and the caller
needs to clean up the stack. There are other conventions, for example,
_stdcall is used for Win32 API functions. For your question, it is true when
you use gcc and run it on GNU/Linux systems. Since it's a default
convention, I assume other compliers will give you the same thing unless you
specify it. But again, I could be wrong in the second case.

-Jamie

There's a whole range of calling conventions available, many of which
do not conform to what you describe above. All The World Is *NOT*
Win32.

"Amit Sharma" <sh*******@gmai l.com> wrote in message
news:fe******** *************** **@posting.goog le.com...
Hi,
I wanted to know when we call function with argument, Does the
arguments stored in stack always or it compiler specific and could be
stored in queue

It depends on your platform (hardware + OS). This is less a C
language question and more a platform-specific question.
e.g. Does this program's output depends upon the compiler specific or
always would be b a

#include<stdio. h>

int a()
{
printf("a\t");
return 0;
}
int b()
{
printf("b\t");
return 0;
}
void c(int a,int b)
{
}
int main()
{
c(a(),b());
return 1;
}
Thanks,
Amit



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----

Nov 14 '05 #8

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

Similar topics

9
2446
by: Chuck Anderson | last post by:
I have a function with 7 inputs. The last three have default values. I want to call that function specifying the first four, skip two and then specify the last. I thought I could write this as : $retval = myfunction(arg1, arg2, arg3, arg4,,,arg7); .... but Php does not seem to want to let me do this. I get a parse
3
14968
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
2
7685
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would like mine to run immediately after it. So in the code below, what JS would i need to add to my "myfile.inc" page so that I could guarantee this behavior? <!-- main page --> <html> <head> <script type="text/javascript">
4
3638
by: anonymous | last post by:
Thanks your reply. The article I read is from www.hakin9.org/en/attachments/stackoverflow_en.pdf. And you're right. I don't know it very clearly. And that's why I want to understand it; for it's useful to help me to solve some basic problem which I may not perceive before. I appreciate your help, sincerely.
21
4140
by: dragoncoder | last post by:
Consider the following code. #include <stdio.h> int main() { int i =1; printf("%d ,%d ,%d\n",i,++i,i++); return 0; }
10
2308
by: Robert Skidmore | last post by:
Take a look at this new JS function I made. It is really simple but very powerful. You can animate any stylesheet numeric value (top left width height have been tested), and works for both % and px values. Works in both ie and firefox. Parameters styleType = top | left | width | height toNumber = the new value of the style then you pass in as many ids as you would like.
3
3663
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules' that takes arguments of type (void *) because the ADT must be able to deal with any type of data. In my actual code, I will code the function to take arguments of their real types, then when I pass this pointer through an interface function, I...
7
1944
by: sfeher | last post by:
Hi All, Is there a way to preserve the arguments across functions? I have: <script> function myFirstFunction() { // arguments = 'param1'
7
3230
by: VK | last post by:
I was getting this effect N times but each time I was in rush to just make it work, and later I coudn't recall anymore what was the original state I was working around. This time I nailed the bastard so posting it before I forgot again... By taking this minimum code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head>
9
3281
by: CryptiqueGuy | last post by:
Consider the variadic function with the following prototype: int foo(int num,...); Here 'num' specifies the number of arguments, and assume that all the arguments that should be passed to this function are of type int. (My question has nothing to do with the definition of the function foo, so don't bother about it.) If I call the function as: foo(2,3,4,5,6,7,8);/*More arguments than expected*/
0
9851
marktang
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...
0
9695
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10902
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10642
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,...
0
10286
tracyyun
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...
1
7824
isladogs
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...
0
7013
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5680
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...
1
4481
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 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.