Hi,
here is the function:
int sum(int a,int b)
{
int c;
c = a + b;
return c;
}
How many spaces will system alloc for
it when calling the function?(4 Bytes
for an int)
I still have a lot of questions that makes
me confuse.such as the return value of
sizeof() func, where to alloc the memory for
the variable of the funcs etc.
And which book will discuss such questions
in detail?
Thanks,
Best Regard!
--
Ryan Wang
email:wangrm1979#at#gmail#dot#com
msn:wangrm1979#at#hotmail#dot#com 10 2307
In article <dl*********@news.cn99.com>,
Ryan Wang <wa*********@windics1.com> wrote: here is the function:
int sum(int a,int b) { int c; c = a + b; return c; }
How many spaces will system alloc for it when calling the function?(4 Bytes for an int)
The amount of memory would depend entirely on the system, compiler,
and compiler options.
On some of the systems I know of, *no* memory would be allocated.
The two integer parameters would be passed in via registers,
the compiler would emit a single "add" instruction on those
registers depositing the result in a third register, and that
third register would happen to be the one in which the return value
would normally be passed back.
On some systems, there would not even be memory allocated for the
return adress.
Other systems... I have seen other systems that would have allocated
a minimum of 86 bytes stack bytes for a function such as that.
Some of the posters are using embedded systems on which there *is*
no stack.
--
Programming is what happens while you're busy making other plans.
Ryan Wang wrote: here is the function:
int sum(int a,int b) { int c; c = a + b; return c; }
How many spaces will system alloc for it when calling the function?(4 Bytes for an int)
The amount of memory required for the code and for the data
varies from one implementation to another and is outside the scope of
Standard C as discussed here. You could look at the output of a
specific compiler to determine its allocation.
I still have a lot of questions that makes me confuse.such as the return value of sizeof() func,
sizeof returns the size of an object or object type in bytes.
where to alloc the memory for the variable of the funcs etc.
For fixed size variables, they are usually defined at the beginning of
the function or beginning of a block where they are used (C99 allows
definition to be placed within a block) . Variables that have the size
decided are runtime as allocated with malloc() and friends.
And which book will discuss such questions in detail?
K&R2 (Kernigan & Richie: The C Programming Language) is a good place to
start. The C FAQ <http://www.eskimo.com/~scs/C-faq/top.html> is another
good resource.
--
Thad
"Ryan Wang" <wa*********@windics1.com> writes: here is the function:
int sum(int a,int b) { int c; c = a + b; return c; }
How many spaces will system alloc for it when calling the function?(4 Bytes for an int)
The allocated space will vary from one implementation to another.
There's seldom any reason you should care, as long as the function
works properly. Why do you want to know?
I still have a lot of questions that makes me confuse.such as the return value of sizeof() func, where to alloc the memory for the variable of the funcs etc.
sizeof is an operator, not a function. It yields the size of its
argument in bytes; the argument can be either an expression or a type
name in parentheses.
--
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.
thanks for all your answers.
Indeed I'm not willing to know all these answers.
I am a Chinese,Software Engineer.Whenever I am
looking for a new job.Such kind of questions always
be asked. And always I give a not correct answer.
I can write programs with no difficulties,but I
don't know such fucking questions's answer.So lost
opptunity severel time.
I am so sorry to waste you to answer such a stupid
question and Really thank you for your help.
--
Ryan Wang
email:wangrm1979#at#gmail#dot#com
msn:wangrm1979#at#hotmail#dot#com
Keith Thompson wrote: [...] sizeof is an operator, not a function. It yields the size of its argument in bytes; the argument can be either an expression or a type name in parentheses.
Since sizeof is an operator, not a function, it might
be best to avoid mentioning its "argument." Operators
have "operands," or in this case "operand."
<Musing> Remember when there used to be different
names for different operands? Augend and addend, minuend
and subtrahend, and the rest? Just about the only such
names one hears nowadays are dividend and divisor. I used
some of the now-unfashionable words in the comments for a
suite of multiple-precision arithmetic functions and got
blank stares at the code review.
However, it's probably a good thing the style has largely
shifted to the generic "operand" as a catch-all -- otherwise,
we'd need to come up with a special name for the operand of
sizeof. Any votes for "measurand?"
--
Eric Sosman es*****@acm-dot-org.invalid
Eric Sosman wrote: <Musing> Remember when there used to be different names for different operands? Augend and addend, minuend and subtrahend, and the rest?
multiplicand
Just about the only such names one hears nowadays are dividend and divisor. I used some of the now-unfashionable words in the comments for a suite of multiple-precision arithmetic functions and got blank stares at the code review.
However, it's probably a good thing the style has largely shifted to the generic "operand" as a catch-all -- otherwise, we'd need to come up with a special name for the operand of sizeof. Any votes for "measurand?"
"sizand"
The operators all seem to have an operand
that begins with at least a partial spelling of the operator.
--
pete
Eric Sosman <es*****@acm-dot-org.invalid> writes: Keith Thompson wrote: [...] sizeof is an operator, not a function. It yields the size of its argument in bytes; the argument can be either an expression or a type name in parentheses.
Since sizeof is an operator, not a function, it might be best to avoid mentioning its "argument." Operators have "operands," or in this case "operand."
Yes, good point.
--
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.
pete wrote: Eric Sosman wrote:
<Musing> Remember when there used to be different names for different operands? Augend and addend, minuend and subtrahend, and the rest?
multiplicand
Yes, of course. Not sure why you didn't mention its
co-operand (co-conspirator?), the multiplier.
Lots of specialized arithmetic or mathematical terms
seem to have fallen out of favor. I've encountered
"abscissa" only a few times, and have never seen "surd"
outside of fiction (the surname of a grouchy professor of
mathematics, whose lovely daughter was Abscissa Surd) or
of comic riddling verse:
But what are all such gaities to me
Whose thoughts are full of indices and surds?
x^2 + 7x + 53 = 11/3.
-- Lewis Carroll
--
Eric Sosman es*****@acm-dot-org.invalid
Eric Sosman wrote: pete wrote: Eric Sosman wrote:
<Musing> Remember when there used to be different names for different operands? Augend and addend, minuend and subtrahend, and the rest?
multiplicand
Yes, of course. Not sure why you didn't mention its co-operand (co-conspirator?), the multiplier.
"multiplicand" was the only other one that I could remember.
I used it recently in a post on this newsgroup.
--
pete
In article <PM********************@comcast.com> Eric Sosman <es*****@acm-dot-org.invalid> writes: pete wrote: Eric Sosman wrote:
<Musing> Remember when there used to be different names for different operands? Augend and addend, minuend and subtrahend, and the rest? multiplicand
Yes, of course. Not sure why you didn't mention its co-operand (co-conspirator?), the multiplier.
dividend and divisor.
I've encountered "abscissa" only a few times, and have never seen "surd" outside of fiction
Ah, sci.math is a work of fiction?
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: hall |
last post by:
Hi.
I have some problems with a class i've written that allocates memory
dynamicaly. I want to put these objects into a std::vector, but it does
not work. My class looks (simplified) like this:
...
|
by: Rex_chaos |
last post by:
I have allocated a array like
double a;
We know that a 1-D array just like an 1-D pointer. So I wonder that
should I release the memory of the array myself like
free(a);
Thanks in...
|
by: Janning Vygen |
last post by:
Hi,
tonight my database got corruppted. before it worked fine.
since two days i do the following tasks every night
psql -c 'CLUSTER;' $DBNAME
psql -c 'VACUUM FULL ANALYZE;' $DBNAME
...
|
by: FI |
last post by:
Hello All,
I am relatively new to C programming and I am struck with a problem in
dynamic memory allocation.
I would like to know if it is ok to pass the 'memory address' returned
by...
|
by: fdmfdmfdm |
last post by:
This is an interview question and I gave out my answer here, could you
please check for me?
Q. What are the memory allocation for static variable in a function,
an automatic variable and global...
|
by: mast2as |
last post by:
This question has been posted to this forum before and I read the
thread but found that the answers were perhaps imcomplete, so I am
trying again.
Whenever I am creating objects I would like to...
|
by: jeungster |
last post by:
Hello,
I'm trying to track down a memory issue with a C++ application that
I'm working on:
In a nutshell, the resident memory usage of my program continues to
grow as the program runs. It...
|
by: Grey Alien |
last post by:
Any one know of an open source memory pool library?. I can't seem to
find any implemented in C (many available in C++ e.g. Boost). Google is
not turning up anything useful ...
|
by: Grey Alien |
last post by:
I am looking to write a very simple memory pool library to store only
one data type at a time - i.e. to provide a contiguous block of memory
to be alloc'd free'd by the calling program. I am
I...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: 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
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |