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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:12:32+00:00 2026-06-03T06:12:32+00:00

My question is regarding statement expressions , which are added as an extension in

  • 0

My question is regarding statement expressions, which are added as an extension in GNU C. Consider the following code:

#include <stdlib.h>
#include <stdio.h>

int main(void)
{
    int i = 0;
    printf("%d\n", i);

    {int i = 1;printf("%d\n", i);}

    printf("%d\n", i);
    return EXIT_SUCCESS;
}

Compiling (gcc -Wall -std=gnu99 lala.c -o lala) and running will yield:

0
1
0

This practice (usage of the extension) is fairly commonplace, notably in container_of in the Linux kernel:

#define container_of(ptr, type, member) ({ \
                const typeof( ((type *)0)->member ) *__mptr = (ptr); 
                (type *)( (char *)__mptr - offsetof(type,member) );})

Similar to this case, I want to define a macro which declares a local variable and does something with it. However, I want to do so without polluting the variable names available at the current scope and avoid possible redefinitions. I was not able to find in the documentation information on how exactly the scoping happens in cases of redefinitions.

In the case above, no warning is issued from the compiler regarding a redefinition. My question is whether I can rely on the fact that the variable scoped inside the statement expression will not affect the variable of the same name in the outer scope?

  • 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-06-03T06:12:33+00:00Added an answer on June 3, 2026 at 6:12 am

    Sure this is safe, this is what scopes are made for.

    (And as dreamlax indicates in his comment, identifiers with two underscores are reserved for the implementation (compiler, library, hosting environement…) so you shouldn’t use them.)

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

Sidebar

Related Questions

I have a question regarding the execution of the following program. #include<stdio.h> int main(void)
I have a question regarding the following code: abstract class a { public static
Quick question regarding memory management in C++ If I do the following operation: pointer
I have a question regarding the ||= statement in ruby and this is of
I have question regarding polymorphism about its assignment statement, for Example this is The
Following my previous question regarding the rationale behind extremely long functions, I would like
I just have a simple question regarding dbms_stats.gather_table_stats. In our application this statement occurs
This is a rather basic question regarding the syntax of the return statement in
i have few question regarding the return statement. a) is it compulsory to define
Question regarding GtkBuilder. When we unref builder pointer does it destroys all the screens/widgets

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.