From saurabh.hirani at gmail.com Mon Dec 27 19:25:10 2010 From: saurabh.hirani at gmail.com (Saurabh Hirani) Date: Tue, 28 Dec 2010 08:55:10 +0530 Subject: [splint-discuss] parse error while using srand Message-ID: Hi, I recently started using splint and found it to be a great tool to gain insights into seemingly innocent code. This is great stuff. I was running splint on one of my programs, and I got a parse error. I narrowed down the search and wrote a sample code which localizes the error: #include #include #include int main() { srand((unsigned int)(time_t *)NULL); char* base_emp_name = "emp"; return(0); } This gives the following error: $ splint debugsplint.c Splint 3.1.2 --- 03 May 2009 debugsplint.c:7:9: Parse Error. (For help on parse errors, see splint -help parseerrors.) *** Cannot continue. the 7th line corresponds to: char* base_emp_name = "emp"; I commented that line out and it worked. #include #include #include int main() { srand((unsigned int)(time_t *)NULL); //char* base_emp_name = "emp"; return(0); } works. I went through splint -help parseerrors and saw that you can surround the unparseable code by # ifndef S_SPLINT_S ... # endif So int main() { srand((unsigned int)(time_t *)NULL); # ifndef S_SPLINT_S char* base_emp_name = "emp"; # endif return(0); } works and so does int main() { # ifndef S_SPLINT_S srand((unsigned int)(time_t *)NULL); # endif char* base_emp_name = "emp"; return(0); } I searched on the net as well as the mailing lists to see if anyone could circumvent this error without making changes to the source but couldn't find any. Can anyone please point me to the right direction and explain why the above snippet generates a parse error and what can I do to avoid such situations in the future? -- thanks and regards, Saurabh From nsriniva at gmail.com Mon Dec 27 22:10:14 2010 From: nsriniva at gmail.com (Naveen Srinivasan) Date: Tue, 28 Dec 2010 11:40:14 +0530 Subject: [splint-discuss] parse error while using srand In-Reply-To: References: Message-ID: Hi Saurabh I am not sure.. But here is what I think... Declarations should be at the beginning of the function before any other code... The parse error might be because you have a declaration following the srand() function. Try putting the 'base_emp_name' declaration before the srand() function. Hopefully, you wouldnt get the parse error (but i think you might get a warning for unused variable) :-) Thanks Naveen On Tue, Dec 28, 2010 at 8:55 AM, Saurabh Hirani wrote: > Hi, > > I recently started using splint and found it to be a great tool to > gain insights into seemingly innocent code. This is great stuff. > > I was running splint on one of my programs, and I got a parse error. I > narrowed down the search and wrote a sample code which localizes the > error: > > #include > #include > #include > > int main() { > srand((unsigned int)(time_t *)NULL); > char* base_emp_name = "emp"; > return(0); > } > > This gives the following error: > > $ splint debugsplint.c > Splint 3.1.2 --- 03 May 2009 > > debugsplint.c:7:9: Parse Error. (For help on parse errors, see splint > -help parseerrors.) > *** Cannot continue. > > the 7th line corresponds to: char* base_emp_name = "emp"; > > I commented that line out and it worked. > > #include > #include > #include > > int main() { > srand((unsigned int)(time_t *)NULL); > //char* base_emp_name = "emp"; > return(0); > } > > works. > > I went through splint -help parseerrors and saw that you can surround the > unparseable code by > > # ifndef S_SPLINT_S > ... > # endif > > So > > int main() { > srand((unsigned int)(time_t *)NULL); > # ifndef S_SPLINT_S > char* base_emp_name = "emp"; > # endif > return(0); > } > > works and so does > > int main() { > # ifndef S_SPLINT_S > srand((unsigned int)(time_t *)NULL); > # endif > char* base_emp_name = "emp"; > return(0); > } > > I searched on the net as well as the mailing lists to see if anyone > could circumvent this error without making changes to the source but > couldn't find any. Can anyone please point me to the right direction > and explain why the above snippet generates a parse error and what > can I do to avoid such situations in the future? > > -- > thanks and regards, > Saurabh > _______________________________________________ > splint-discuss mailing list > splint-discuss at mail.cs.virginia.edu > http://www.cs.virginia.edu/mailman/listinfo/splint-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.cs.virginia.edu/pipermail/splint-discuss/attachments/20101228/8a7c1a8b/attachment.html From saurabh.hirani at gmail.com Tue Dec 28 00:05:00 2010 From: saurabh.hirani at gmail.com (Saurabh Hirani) Date: Tue, 28 Dec 2010 13:35:00 +0530 Subject: [splint-discuss] parse error while using srand In-Reply-To: References: Message-ID: Hey Naveen, That did the trick. But it's a pain to declare all the variables in advance as it clutters up a logical block of flow. But at least that makes me proceed ahead with the rest of the work. Will use that. Thanks for the prompt and clear response. Cheers, Saurabh. From splint at sympatico.ca Tue Dec 28 16:57:29 2010 From: splint at sympatico.ca (splint at sympatico.ca) Date: Tue, 28 Dec 2010 19:57:29 -0500 Subject: [splint-discuss] parse error while using srand In-Reply-To: (Saurabh Hirani's message of "Tue, 28 Dec 2010 13:35:00 +0530") References: Message-ID: On 28 Dec 2010, saurabh.hirani at gmail.com wrote: > That did the trick. But it's a pain to declare all the variables in > advance as it clutters up a logical block of flow. But at least that > makes me proceed ahead with the rest of the work. Will use that. > Thanks for the prompt and clear response. Could you retry with splint CVS code? We have put support in for c99 declarations. -- Humility is no substitute for a good personality. - Fran Lebowitz From saurabh.hirani at gmail.com Tue Dec 28 19:40:16 2010 From: saurabh.hirani at gmail.com (Saurabh Hirani) Date: Wed, 29 Dec 2010 09:10:16 +0530 Subject: [splint-discuss] parse error while using srand In-Reply-To: References: Message-ID: Sure. Will try it out and update the list. On Wed, Dec 29, 2010 at 6:27 AM, wrote: > On 28 Dec 2010, saurabh.hirani at gmail.com wrote: > >> That did the trick. But it's a pain to declare all the variables in >> advance as it clutters up a logical block of flow. But at least that >> makes me proceed ahead with the rest of the work. Will use that. >> Thanks for the prompt and clear response. > > Could you retry with splint CVS code? ?We have put support in for c99 > declarations. > > -- > Humility is no substitute for a good personality. ?- Fran Lebowitz > _______________________________________________ > splint-discuss mailing list > splint-discuss at mail.cs.virginia.edu > http://www.cs.virginia.edu/mailman/listinfo/splint-discuss > -- Saurabh