473,324 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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 microcontrollers). I just want to know if a
program to be compiled by a conformant compiler needs to be careful with
argv[0].

Nov 13 '05 #1
2 7076
August Derleth <li*****************@onewest.net> wrote:
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?


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.

Nov 13 '05 #2
August Derleth wrote:
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?


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
rg********@pobox.com
Remove the 'g' from my address to send me mail.
Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: mahurshi | last post by:
i have a quick question i am putting a debug flag in my program (i really dont need this feature, but i figured it might be useful when i get into trouble) so i want to check if argv is the...
14
by: Hal Styli | last post by:
Is this a style thing? int main(int argc, char *argv ) or int main(int argc, char **argv ) i.e. *argv or **argv Why choose the latter?
5
by: jab3 | last post by:
(again :)) Hello everyone. I'll ask this even at risk of being accused of not researching adequately. My question (before longer reasoning) is: How does declaring (or defining, whatever) a...
3
by: junky_fellow | last post by:
Where does the storage is allocated for the various argument strings (char *argv) passed to the main() ? In main() we never allocate space for these. So, which function does it and how does it...
32
by: mnaydin | last post by:
Assume the main function is defined with int main(int argc, char *argv) { /*...*/ } So, is it permitted to modify the argv array? The standard says "The parameters argc and argv and the strings...
2
by: ais523 | last post by:
I've been wondering about the compatibility of pointers to signed, unsigned and plain char, and it's not clear to me how interchangeable they are. Is the following portable? int main(int argc,...
6
by: CJ | last post by:
Functions can accept "argv like" variable definitions, i.e. foo(int argc, char *argv), which was defined/initialized in the C start up stubs, but we can't declare one for our own use. Example: ...
17
by: Matt | last post by:
Hello. I'm having a very strange problem that I would like ot check with you guys. Basically whenever I insert the following line into my programme to output the arguments being passed to the...
8
by: Richard Heathfield | last post by:
candide said: I don't think it says so in exactly those words (and if it does, I'd argue that it's wrong). Certainly I can't find such wording on a cursory look through that section. Okay,...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.