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 6629193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:13:32+00:00 2026-05-25T22:13:32+00:00

Recently I had to modify a legacy code that was compiled with a very

  • 0

Recently I had to modify a legacy code that was compiled with a very old version of GCC (somewhere around version 2.3). Within a function, variable had to be declared before being used. I believe this is done C89 standard. This limitation is later removed.

My question is: Back then, why did they enforce this ruling? Was there any concern that could jeopardise the integrity of the software?

  • 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-25T22:13:33+00:00Added an answer on May 25, 2026 at 10:13 pm

    Variables still have to be declared before being used — and they’ve never had to be declared just at the top of a function.

    The C89 requirement is that a block consists of an opening {, followed by zero or more declarations, followed by zero or more statements, followed by the closing }.

    For example, this is legal C89 (and, without the void, even K&R C, going back to 1978 or earlier):

    int foo(void) {
        int outer = 10;
        {
             int inner = 20;
             printf("outer = %d, inner = %d\n", outer, inner);
        }
        printf("outer = %d, inner is not visible\n", outer);
        return 0;
    }
    

    C99 loosened this, allowing declarations and statements to be mixed within a block:

    int foo(void) {
        int x = 10;
        printf("x = %d\n", x);
        int y = 20;
        printf("y = %d\n", y);
        return 0;
    }
    

    As for the reason for the original restriction, I think it goes back to C’s ancestor languages: B, BCPL, and even Algol. It probably did make the compiler’s job a bit easier. (I was thinking that it would make parsing easier, but I don’t think it does; it still has to be able to distinguish whether something is a declaration or a statement without knowing in advance from the context.)

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

Sidebar

Related Questions

We recently had a code review . One of my classes was used so
I recently had a little problem using a jquery plugin with coffeescript (within the
I recently had this issue with a client. The code read: ini_set( sendmail_from, noreply@<current-domain>.com
I recently had a rather strange phenomenon. Had to obtain a count that included
I recently had a discussion with another developer who claimed to me that JOINs
For a given MySQL DB that I use and modify occasionally I had to
I recently had an interview at a small company that wants to greatly increase
Having recently had reason to peruse the Nullable documentation, I noticed that the definition
I recently had this idea to create a C# Windows Form App that enables
I recently had a need to interpret a DEC 32-bit floating point representation. It

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.