Problem with running lint


 
Thread Tools Search this Thread
Top Forums Programming Problem with running lint
# 1  
Old 10-16-2014
Problem with running lint

This is a strange problem that I can't figure out - I run lint on my C programs to weed out unused variables. The output can be quite large, so I use sed to cut out just unused variables section. The typical command looks like this:
Code:
 lint -I /usr/local/include  -I./include -m hn.c

As my includes can be in different places I put together a small script to build the proper -I directivesf or lint. When I run the script somehow lint can not follow -I directive. See the script below, I added echo just to show the command to be executed. When I cut/paste the command it runs without any issue:

Code:
 #!/bin/ksh
 INCL="-I /usr/local/include ";
if [ -d include ]; then
        INCL="${INCL} -I./include"; 
elif [ -d ../include ]; then
        INCL="${INCL} -I../include"; 
fi
 echo "COMMAND: " lint "${INCL}" -m "$1";
echo;
 lint "${INCL}" -m "$1" | sed -n '/variable unused/,/^$/p'

This is the example input for the lint:

Code:
 
 $ ls *.c include 
hn.c
 include:
hn1.h
  
 $ cat include/hn1.h 
#define MAX_SZ 1024
  
 #include <hn1.h>
 static  double  arr[MAX_SZ];
static  double  k = 1.0;
 
double  get_hn1()
{
  int           i, n;
  double        tot = 0;
         for(i = 0; i < MAX_SZ; i++)
        {
                tot += k * arr[i];
        }
        return(tot);
}

When I run the script, it can't see the hn1.h
Code:
 $ ./lnt hn.c
COMMAND:  lint -I /usr/local/include  -I./include -m hn.c
 "hn.c", line 1: error: cannot find include file: <hn1.h>
variable unused in function
lint: errors in hn.c; no output created
lint: pass2 not run - errors in hn.c
    (9) n in get_hn1

Now I cut/paste the command from above:

Code:
 $ lint -I /usr/local/include  -I./include -m hn.c
 variable unused in function
    (9) n in get_hn1
 name defined but never used
    get_hn1             hn.c(8)

Any idea why lint is not happy within the script?
# 2  
Old 10-16-2014
I think you are quoting a little too aggressively. Try ${INCL} instead of "${INCL}" to let it split on spaces instead of cramming it into lint as one giant argument.

To see the difference, try printf "%s\n" "${INCL}" vs printf "%s\n" ${INCL}
# 3  
Old 10-16-2014
You are right, removing double quotes around ${INCL} helped. Puzzle solved. Thank you!

I don't know how to tag it as solved.

Last edited by migurus; 10-16-2014 at 09:48 PM.. Reason: should be tagged as solved
This User Gave Thanks to migurus For This Post:
# 4  
Old 10-16-2014
Quote:
Originally Posted by migurus
I don't know how to tag it as solved.
Look at the top of every page in any thread you start. You will see the words "Edit Tags". Select those words to edit the tags for your thread (including the "solved" tag).

I have added the tags "lint" and "solved" to this thread for you.
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Lint Command in unix

the thread is deleted (1 Reply)
Discussion started by: jhon1257
1 Replies

2. UNIX for Advanced & Expert Users

lint in unix

Hi All, Can any one help me in how to run "lint command " on .c files to list all functions with wrong return value in hp unix. Thanks in Advance. (1 Reply)
Discussion started by: jhon1257
1 Replies

3. Shell Programming and Scripting

Problem on running a script

Hi all, Running follow command on terminal; $ glance -T cloudlive -I ubuntu -K ubuntu123 -N \ http://127.0.0.1:5000/v2.0/OpenX add name="cirros" is_public=true \ container_format=ovf disk_format=raw < \ /srv/cirros-0.3.0-x86_64-disk.img It works without problem. Putting it on a... (5 Replies)
Discussion started by: satimis
5 Replies

4. UNIX for Dummies Questions & Answers

Problem running executable with ./

Hey all, I'm trying to execute a program and despite it appearing to be there, I keep getting this: -bash: ./aisdispatcher: No such file or directoryTo run it, I'm going into the directory where it is stored and running ./aisdispatcher...the result of which should just be a listing of options... (10 Replies)
Discussion started by: pmd006
10 Replies

5. High Performance Computing

Problem running mpirun

Hi, I have a difficulty running mpirun on my workstation, RHEL 4. I have uninstalled lam-7.1.4 with 'rpm -e lam-7.1.4'. No problem. The I downloaded openmpi-1.3.tar.gz. unzipped as normal. No problem. Then did 'make clean'. Then './configure'. No problems. Then I did 'make' and then 'make... (1 Reply)
Discussion started by: The_Watcher
1 Replies

6. AIX

[AIX] usages of lint for .cpp file?

Hi , I Want to apply AIX lint to my source code which all are *.cpp/*.h >lint test.cpp lint: 1286-332 File test.cpp must have a .c, .C or .ln extension. It is ignored. lint: 1286-334 There are no files to process. I am getting above error. -Ashok (3 Replies)
Discussion started by: ashokd001
3 Replies

7. Shell Programming and Scripting

lint and CFLAGS

I often find myself running lint in the following fashion: lint -Idir-1 ... -Idir-n some-src.c where a number of -Idirs should be coming from the make file. Here is example: $ cd dir1 $ grep ^CF makefile CFLAGS = -g -I ../ver1/include $ lint -I ../ver1/include sr1.c ... (0 Replies)
Discussion started by: migurus
0 Replies

8. Programming

lint comments

Hi can anyone help me regarding the meaning of the following lint messages. what is the use of having such lint comments in the c program. /*lint -esym(534,cputs,fgets,cprintf) */ /*lint -efile(766,pragmas.h) */ Thanks a lot in advance. (5 Replies)
Discussion started by: axes
5 Replies

9. UNIX for Dummies Questions & Answers

Purpose of lint in UNIX

Can Any One let me know abut the use on "lint" in UNIX...... (1 Reply)
Discussion started by: kumar_saurabh
1 Replies

10. Programming

Help from lint experts needed

how can i check my code with lint? What if the code containes multiple module? The check is been done on each module separately? What is the command to use the lint Any relevant site??? Thanks a lot. You are doing a great job.:cool: (2 Replies)
Discussion started by: amatsaka
2 Replies
Login or Register to Ask a Question