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 7 3283
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
In <fe*************************@posting.google.com> 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
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.disclaimer>
_
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
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*******@gmail.com> wrote in message
news:fe*************************@posting.google.co m... 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! =-----
"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_Keith) 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.
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?
"Jamie Lin" <ja***@tildefoo.com> wrote in message news:<41********@corp.newsgroups.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*******@gmail.com> wrote in message news:fe*************************@posting.google.co m... 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! =----- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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) {...
|
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...
|
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...
|
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;
}
|
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...
|
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'...
|
by: sfeher |
last post by:
Hi All,
Is there a way to preserve the arguments across functions?
I have:
<script>
function myFirstFunction()
{
// arguments = 'param1'
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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: 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,...
|
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,...
| |