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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:11:48+00:00 2026-06-17T07:11:48+00:00

Suppose these code compiled in g++ : #include <stdlib.h> int main() { int a

  • 0

Suppose these code compiled in g++:

#include <stdlib.h>

int main() {
    int a =0;

    goto exit;

    int *b = NULL;

exit:
    return 0;
}

g++ will throw errors:

goto_test.c:10:1: error: jump to label ‘exit’ [-fpermissive]
goto_test.c:6:10: error:   from here [-fpermissive]
goto_test.c:8:10: error:   crosses initialization of ‘int* b’

It seems like that the goto can not cross pointer definition, but gcc compiles them ok, nothing complained.

After fixed the error, we must declare all the pointers before any of the goto statement, that is to say you must declare these pointers even though you do not need them at the present (and violation with some principles).

What the origin design consideration that g++ forbidden the useful tail-goto statement?


Update:

goto can cross variable (any type of variable, not limited to pointer) declaration, but except those that got a initialize value. If we remove the NULL assignment above, g++ keep silent now. So if you want to declare variables that between goto-cross-area, do not initialize them (and still violate some principles).

  • 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-17T07:11:49+00:00Added an answer on June 17, 2026 at 7:11 am

    Goto can’t skip over initializations of variables, because the respective objects would not exist after the jump, since lifetime of object with non-trivial initialization starts when that initialization is executed:

    C++11 §3.8/1:

    […] The lifetime of an object of type T begins when:

    • storage with the proper alignment and size for type T is obtained, and

    • if the object has non-trivial initialization, its initialization is complete.

    C++11 §6.7/3:

    It is possible to transfer into a block, but not in a way that bypasses declarations with initialization. A
    program that jumps from a point where a variable with automatic storage duration is not in scope to a
    point where it is in scope is ill-formed unless the variable has scalar type, class type with a trivial default
    constructor and a trivial destructor, a cv-qualified version of one of these types, or an array of one of the
    preceding types and is declared without an initializer (8.5).

    Since the error mentions [-fpermissive], you can turn it to warning by specifying that compiler flag. This indicates two things. That it used to be allowed (the variable would exist, but be uninitialized after the jump) and that gcc developers believe the specification forbids it.

    The compiler only checks whether the variable should be initialized, not whether it’s used, otherwise the results would be rather inconsistent. But if you don’t need the variable anymore, you can end it’s lifetime yourself, making the “tail-goto” viable:

    int main() {
        int a =0;
        goto exit;
        {
            int *b = NULL;
        }
    exit:
        return 0;
    }
    

    is perfectly valid.

    On a side-note, the file has extension .c, which suggests it is C and not C++. If you compile it with gcc instead of g++, the original version should compile, because C does not have that restriction (it only has the restriction for variable-length arrays—which don’t exist in C++ at all).

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

Sidebar

Related Questions

Suppose that we have a simple c code: #include <stdio.h> #include <stdlib.h> int main(int
This is my C code, compiled with gcc. #include<stdio.h> int main() { int a=1;
Suppose we have the following code: #include <iostream> class Person{ public: Person(int age); int
Suppose I have these domain objects: DataPoint ========= public int Id {get;set;} public int
Let us suppose i have these three methods defined: int F1(int, int); int F1(float,
Suppose there is the following code: private static int DoSwitch(string arg) { switch (arg)
I've 2 mysql select statements, suppose these are my queries & their result :
Suppose you have these modules: module1.py import module2 def a(): module1.b() def c(): print
Suppose you have these tables: Table Name: Salesman Fields: S_ID(Primary Key), Name Table Name:
Suppose the following route: {region}/{storehouse}/{controller}/{action} These two parameters region and storehouse altogether identify a

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.