• Post Reply Bookmark Topic Watch Topic
  • New Topic

In c Is function calling is same as method calling in Java ?  RSS feed

 
Nikhil Sagar
Ranch Hand
Posts: 216
Java Linux Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean in java we have a concept of stack for method calling and also for local variable ?
But in c is there is also stack concept or any other concept ?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not clear what you're asking.

In both C and Java, invoking a "subroutine"--whether it's called a "function" or a "method" in that particular language--involves creating a stack frame for parameters, return value, and PC. The details of what goes on that stack frame and in what order are of course different. And method calling in Java involves things like polymorphism and a "current object" that don't exist in C.

I have no idea what you mean by "stack concept of any other concept".

What is it you're actually trying to understand?
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, unless you get into pointers and pass-by-reference arguments.

Most modern and older (ala Forth) languages have a stack as a core component.

WP
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William P O'Sullivan wrote:pass-by-reference arguments.


Well, since neither C nor Java supports PBR, that bit is irrelevant.
 
Nikhil Sagar
Ranch Hand
Posts: 216
Java Linux Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i mean in a simple c program like this


here in this code function calling is following the concept of stack or any other concept ?
 
Nikhil Sagar
Ranch Hand
Posts: 216
Java Linux Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:It's not clear what you're asking.

In both C and Java, invoking a "subroutine"--whether it's called a "function" or a "method" in that particular language--involves creating a stack frame for parameters, return value, and PC. The details of what goes on that stack frame and in what order are of course different. And method calling in Java involves things like polymorphism and a "current object" that don't exist in C.

I have no idea what you mean by "stack concept of any other concept".

What is it you're actually trying to understand?


sorry jeff it is "stack concept or any other concept".
sorry it was my mistake.
i have edited it now.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nikhil Sagar wrote:i mean in a simple c program like this


here in this code function calling is following the concept of stack or any other concept ?


As I already stated, when you invoke those functions, a stack will be used.

 
Nikhil Sagar
Ranch Hand
Posts: 216
Java Linux Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay Okay jeff now i got it.
Thanks again jeff.
Thanks William.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
Tim Holloway
Saloon Keeper
Posts: 18800
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In abstract terms, you call a function, but you invoke a method.

Functions are procedure-oriented, but methods are object-oriented. A few languages support both paradigms concurrently. The best-known of which is C++.

FORTRAN in its original form also discriminated between subroutines and functions as did some of its contemporaries and descendants. A function gets its name from its mathematical forebear, which has a range (input) and domain (output), although in architectural terms, the computer term became assigned to a subroutine (callable code procedure) that had a method of returning results. So a FORTRAN "SUBROUTINE" statement was the early version of a function returning void.

As far as stacks go, pretty much any programming language that permits recursive procedures has some sort of stack basis. FORTRAN and COBOL did not originally support recursion in their strictest forms, which was fortunate for IBM, since the System/360 and System/370 systems had no stack hardware and had to do that kind of stuff the hard way.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!