When referring to the conforming declaration for main, Lint displays
Info 818: Pointer parameter 'argv' (line 3) could be declared as
pointing to const
Presumably it's saying that the definition could be:
int main(int argc, char *const *argv)
Why didn't C89 mandate that?
--
Martin 7 3516
Martin <ma************ ***********@whi ch.tnetwrites:
When referring to the conforming declaration for main, Lint displays
Info 818: Pointer parameter 'argv' (line 3) could be declared as
pointing to const
Presumably it's saying that the definition could be:
int main(int argc, char *const *argv)
Why didn't C89 mandate that?
Back in 1989, the "const" keyword was new; many pre-ANSI compilers
didn't recognize it, and would have reported a syntax error.
Requiring "const" would have broken existing code.
Note also that the standard specifically requires the parameters argc
and argv, and the strings pointed to by the argv array, to be
modifiable. It's not clear whether the char* elements of the argv
array itself are modifiable; if they are, then requiring "const" here
would break that.
Probably lint (note that there are a number of lint implementations )
is issuing this message because your code didn't happen to modify
these pointers. What happens if you change your function's name from
"main" to something else?
--
Keith Thompson (The_Other_Keit h) <ks***@mib.or g>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
On Sat, 01 Mar 2008 21:43:34 -0000, Keith Thompson <ks***@mib.orgw rote:
Probably lint (note that there are a number of lint
implementations ) is issuing this message because
your code didn't happen to modify these pointers.
What happens if you change your function's name
from "main" to something else?
I get the same message from Lint.
I am using PC-lint for C/C++ (NT) Ver. 8.00L, with the options -W -ansi
-pedantic -Wall.
--
Martin
Martin <ma************ ***********@whi ch.tnetwrites:
On Sat, 01 Mar 2008 21:43:34 -0000, Keith Thompson <ks***@mib.orgw rote:
>Probably lint (note that there are a number of lint implementation s) is issuing this message because your code didn't happen to modify these pointers. What happens if you change your function's name from "main" to something else?
I get the same message from Lint.
I am using PC-lint for C/C++ (NT) Ver. 8.00L, with the options -W
-ansi -pedantic -Wall.
So it looks like PC-lint is recommending that anything that your code
doesn't happen to modify should be declared as const (not bad advice
IMHO), but it's not allowing for the fact that the "main" function is
a special case.
--
Keith Thompson (The_Other_Keit h) <ks***@mib.or g>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Keith Thompson wrote:
Martin <ma************ ***********@whi ch.tnetwrites:
>On Sat, 01 Mar 2008 21:43:34 -0000, Keith Thompson <ks***@mib.orgw rote:
>>Probably lint (note that there are a number of lint implementatio ns) is issuing this message because your code didn't happen to modify these pointers. What happens if you change your function's name from "main" to something else?
I get the same message from Lint.
I am using PC-lint for C/C++ (NT) Ver. 8.00L, with the options -W -ansi -pedantic -Wall.
So it looks like PC-lint is recommending that anything that your code
doesn't happen to modify should be declared as const (not bad advice
IMHO), but it's not allowing for the fact that the "main" function is
a special case.
Seems to me that `const' is appropriate only if the
non-modification is part of the "contract" or "interface"
of the function. The fact that today's version of the
function doesn't modify something is not necessarily a
promise that tomorrow's version will do likewise. Take
lint's advice as advice, not as a command.
In fact, that's the way to approach all of lint's
advice. Lint's job is to be a Nervous Nellie, to see a
lurking felon in every shadow and a goblin hiding beneath
every bed. Many of the felons and goblins will turn out
to be imaginary, but it behooves you to shine a few lights
in the shadows and poke under the beds with broomsticks,
just in case. See also the First Commandment at http://www.lysator.liu.se/c/ten-commandments.html
--
Eric Sosman es*****@ieee-dot-org.invalid
My thanks Keith and Eric. I've just looked at the C89 Standard
<http://flash-gordon.me.uk/ansi.c.txtand found the key paragraph:
The parameters argc and argv and the strings pointed
to by the argv array shall be modifiable by the
program, and retain their last-stored values between
program startup and program termination.
-- 2.1.2.2
--
Martin
Martin wrote:
>
My thanks Keith and Eric. I've just looked at the C89 Standard
<http://flash-gordon.me.uk/ansi.c.txtand found the key paragraph:
The parameters argc and argv and the strings pointed
to by the argv array shall be modifiable by the
program, and retain their last-stored values between
program startup and program termination.
-- 2.1.2.2
WARNING: do not attempt to lengthen the strings.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
--
Posted via a free Usenet account from http://www.teranews.com
On Mon, 03 Mar 2008 22:35:08 -0000, CBFalconer <cb********@yah oo.com>
wrote:
Martin wrote:
>> My thanks Keith and Eric. I've just looked at the C89 Standard <http://flash-gordon.me.uk/ansi.c.txtand found the key paragraph:
The parameters argc and argv and the strings pointed to by the argv array shall be modifiable by the program, and retain their last-stored values between program startup and program termination. -- 2.1.2.2
WARNING: do not attempt to lengthen the strings.
Well, that's certianly worth knowing, but it doesn't seem to be explicit
in the paragraph I quoted.
--
Martin This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Robin Sanderson |
last post by:
Sorry in advance if this is a stupid question - I am new to C++.
In the process of converting program to be run from the command line
into a function to be run from another program I noticed behaviour
that I do not understand. Consider the example programs below:
Program 1 below is a simple program that merely outputs the command
line arguments. This compiles and runs fine with Microsoft Visual C++
6.0 and g++ 3.3.1.
|
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 variable **var make it an array of pointers?
I realize that 'char **var' is a pointer to a pointer of type char (I hope).
And I realize that with var, var is actually a memory address (or at
|
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 pointed to by the
argv array shall be modifiable by the program,". According to
my reading of the standard, for example, ++argv and ++argv
are both permitted, but not ++argv because it says nothing about
the argv array itself. Is my...
|
by: broeks |
last post by:
I'm trying to create an array of character arrays. I would use strings,
but the function I need to feed into looks like this
int execve(const char *filename, char *const argv , char *const
envp ). I know this is not a C++ function, and I only ask for how to
create something that a function like this will actually accept.
I will not know the amount of character arrays (arguments) until
runtime, so I need to use new or calloc to get this...
|
by: Joe Smith |
last post by:
It is nothing short of embarrassing to feel the need to ask for help on
this. I can't see how I would make the main control for this. What I want
is a for loop and a test condition. And while I know, from things I
pondered 2 decades ago, that a fella can write code without a goto, I'm
stuck.
/* sieve1.c */
#define whatever 20
#define N whatever
| |
by: Eric |
last post by:
Hi
For this code,
int getopt (int argc, char *const argv, const char *opts)
what does the "char *const argv" mean? Does it equal to "char **const
argv"?
Or "char *const *argv"? Which is the const?
Thanks
|
by: interec |
last post by:
Hi Folks,
I am writing a c++ program on redhat linux using main(int argc,
wchar_t *argv). $LANG on console is set to "en_US.UTF-8". g++
compiler version is 3.4.6.
Q1. what is the encoding of data that I get in argv ?
Q2. what is encoding of string constants defined in programs (for
example L"--count") ?
|
by: vicky |
last post by:
hi all,
please tell me with example, how the *argv point to the the no of
strings.
|
by: jorba101 |
last post by:
On my platform, I see that if I do following:
void myFunc( const char *myArg )
{
char **argv;
argv = &myArg;
createTask( ....., argv, .... );
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |