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

  • SEARCH
  • Home
  • 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 88621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:35:19+00:00 2026-05-10T22:35:19+00:00

I long thought that in C, all variables had to be declared at the

  • 0

I long thought that in C, all variables had to be declared at the beginning of the function. I know that in C99, the rules are the same as in C++, but what are the variable declaration placement rules for C89/ANSI C?

The following code compiles successfully with gcc -std=c89 and gcc -ansi:

#include <stdio.h> int main() {     int i;     for (i = 0; i < 10; i++) {         char c = (i % 95) + 32;         printf('%i: %c\n', i, c);         char *s;         s = 'some string';         puts(s);     }     return 0; } 

Shouldn’t the declarations of c and s cause an error in C89/ANSI mode?

  • 1 1 Answer
  • 3 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. 2026-05-10T22:35:20+00:00Added an answer on May 10, 2026 at 10:35 pm

    It compiles successfully because GCC allows the declaration of s as a GNU extension, even though it’s not part of the C89 or ANSI standard. If you want to adhere strictly to those standards, you must pass the -pedantic flag.

    The declaration of c at the start of a { } block is part of the C89 standard; the block doesn’t have to be a function.

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

Sidebar

Related Questions

Long version: Those familiar to the standardization nightmare of the RSS-family, may know that
I'm working on a Function that will do a POW long handed. It's an
This is a long shot, but does anyone know of an algorithm for estimating
I've got a form that's a few pages long. To traverse the form all
Alright, so I'm about 90% sure that this isn't possible, but I thought I'd
Misra says to ban all unions. I also know that deviations are allowed as
Long introduction: Normally all data necessary for my web application are stored in session
Long story short, we found files promoting prescription drugs on our server that we
Read some texts about locking in PHP. They all, mainly, direct to http://php.net/manual/en/function.flock.php .
I have a field that is dynamically being filled. I know that the first

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.