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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:56:00+00:00 2026-05-11T01:56:00+00:00

I looked in Stevens , and in the Posix Programmer’s Guide , and the

  • 0

I looked in Stevens, and in the Posix Programmer’s Guide, and the best I can find is

An array of strings called the enviroment is made available when the process begins. This array is pointed to by the external variable environ, which is defined as:

extern char **environ;

It’s that environ variable that has me hesitating. I want to say

-The calling process/shell has already allocated the block of null terminated strings

-the ‘external’ variable environ is used as the entry point by getenv().

–ipso facto feel free to call getenv() within a static initializer.

But I can’t find any guarantee that the ‘static initialization’ of environ precedes all the other static initialization code. Am I overthinking this?

Update

On my platform (AMD Opteron, Redhat 4, GCC 3.2.3), setting LD_DEBUG shows that environ gets set before my static initializers are called. This is a nice thing to know; thanks, @codelogic. But it is not necessarily the result I’d get on all platforms.

Also, while I agree intuitively with @ChrisW on the behavior of the C/C++ runtime library, this is just my intuition based on experience. So anyone who can pipe up with a quote from someplace authoritative guaranteeing that environ is there before static initializers are called, bonus points!

  • 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-11T01:56:01+00:00Added an answer on May 11, 2026 at 1:56 am

    I think you can run your program with LD_DEBUG set to see the exact order:

    LD_DEBUG=all <myprogram> 

    EDIT: If you look at the source code of the runtime linker (glibc 2.7), specifically in files:

    • sysdeps/unix/sysv/linux/init-first.c
    • sysdeps/i386/init-first.c
    • csu/libc-start.c
    • sysdeps/i386/elf/start.S

    you will see that argc, argv and environ (alias for __environ) are set before any global constructors are called (the init functions). You can follow the execution starting right from _start, the actual entry point (start.S). As you’ve quoted Stevens ‘An array of strings called the enviroment is made available when the process begins’, suggesting that environment assignment happens at the very beginning of the process initialization. This backed by the linker code, which does the same, should give you sufficient peace of mind 🙂

    EDIT 2: Also worth mentioning is that environ is set early enough that even the runtime linker can query it to determine whether or not to output verbosely (LD_DEBUG).

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

Sidebar

Related Questions

I looked through other questions and couldn't find what I needed. Best if I
Looked into UIKeyboardAnimationDurationUserInfoKey but I just can't find anywhere how to set it to
I looked all over the NSString class reference but I can't seem to find
I looked around here and i can't find an answer to this. It might
I looked around and couldn't find it! Maybe I didn't look hard enough,but this
Looked around, couldn't find this specific question discussed. Pretty sure the difference is negligible,
I looked up in the net, but cannot find any answer (maybe my search
Ive looked for some examples online but i couldn't fund any. how can i
looked around here, but didn't find straightforward answer.. I'm using cookies, to store last
i looked at Test C code with googletest but did not find any satisfactory

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.