Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5959583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:42:19+00:00 2026-05-22T18:42:19+00:00

I assumed that one of the most used system functions ( ls ) of

  • 0

I assumed that one of the most used system functions (ls) of one of the most famous OSs (linux) written by one of the most authoritative programmers (Richard Stallman) could be an example of really well written code.

So, being it open source, I decided to have a look at the code (see e.g. here). There I found several functions defined after the main(), hence after their call, which I expected to be quite uncommon.

Will any experienced C programmer comment on this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:42:20+00:00Added an answer on May 22, 2026 at 6:42 pm

    There’s absolutely nothing wrong with what Stallman did here.

    The C language permits the forward declaration of a function that will be defined afterwards.

    This has many advantages, and should not be considered as bad behavior, but rather very good behavior.

    Advantages (not exhaustive):
    – give the programmer a vision of the API exposed by the C code in a quick look, without having to look at all the code
    – permits the use of header files, where you declare a function that will be defined later on in the compilation process. So that you don’t have to define your function every time you use it..

    In the case of this ls implementation, he simply pre-declared the functions that he’ll use in the main(), but if you look carefully, the main function is the first one to appear.
    This is most probably for the sake of readability, so that you don’t have to scroll all the way down to reach the entry point of the program.

    Note that the vocabulary is important here:
    – function declaration means: just tells the compiler that, somewhere in your code, a function with the same name will be defined.
    – function definition : the actual function implementation

    int my_function( char *text); // function declaration, no implementation
    int main( int argc, char **argv)
    {
       return my_function(argv[0]); // use of the declared function
    }
    
    // actual function definition / implementation
    int my_function( char *text )
    {
       printf("%s\n", text);
    }
    

    Edit: after looking more carefully to the code, you can see that Stallman didn’t forward-declare all his functions. He has also a rather strange manner of defining functions. I attribute this to the oldness of the code, which is dated of 1985, when the C compiler was not as well defined as today.
    It must have permitted this kind of function usage before being declared or defined.

    Last but not least, the recent version of ls source code can be found here: http://coreutils.sourcearchive.com/documentation/7.4/ls_8c-source.html ,
    with much more C99-compliant coding than the ’85 (Back-to-the-Future) version.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason I have always assumed that most of the time a variable
I'm building a web application that is aimed at developers. I assumed that most
I'm creating a PHP CMS, one that I hope will be used by the
(For the purposes of this question, let us assume that one is intentionally not
Let's assume that I can't script the loaded swf, nor can the loaded one
I assumed that I would be able to create 2 different omp_lock_t's, and lock
I assumed that this would provide me with the list of follower names instead
I have assumed that if instance variables are managed by spring IOC, and are
Possible Duplicate: Loop code for each file in a directory I assumed that I
I have had to make changes to a trigger and assumed that running an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.