Is argv[0] guaranteed to be a valid pointer?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • August Derleth

    #1

    Is argv[0] guaranteed to be a valid pointer?

    What does the C Standard (any of them) say about this issue? Can a
    conformant implementation allow argv[0] == NULL? Can a conformant
    implementation allow argv[0] to cause the machine to segfault if it is
    dereferenced?

    I understand, I think, the difference between hosted implementations and
    freestanding ones (as in microcontroller s). I just want to know if a
    program to be compiled by a conformant compiler needs to be careful with
    argv[0].

  • Kevin Easton

    #2
    Re: Is argv[0] guaranteed to be a valid pointer?

    August Derleth <libertarian232 003**@onewest.n et> wrote:[color=blue]
    > What does the C Standard (any of them) say about this issue? Can a
    > conformant implementation allow argv[0] == NULL? Can a conformant
    > implementation allow argv[0] to cause the machine to segfault if it is
    > dereferenced?[/color]

    argc can be 0, which case argv[0] == NULL.

    argv[0] must be either NULL, or a pointer to a string. If argc is
    non-zero, argv[0] cannot be NULL.

    - Kevin.

    Comment

    • Russell Hanneken

      #3
      Re: Is argv[0] guaranteed to be a valid pointer?

      August Derleth wrote:[color=blue]
      > What does the C Standard (any of them) say about this issue? Can a
      > conformant implementation allow argv[0] == NULL? Can a conformant
      > implementation allow argv[0] to cause the machine to segfault if it is
      > dereferenced?[/color]

      argv[0] can be NULL only if argc is 0. If argc is greater than 0, argv[0]
      must be a valid string, although it might be an empty string (i.e.,
      argv[0][0] might be '\0').

      I'm looking at the C99 standard. I don't know what C89 says.

      --
      Russell Hanneken
      rghanneken@pobo x.com
      Remove the 'g' from my address to send me mail.


      Comment

      Working...