Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

detect hardcodings in C/C++
Hi,
I wish to scan C/C++ code and detect any hard coded statements in it,
like the '1000' in:
char str[1000];

or the '10' in:
int i = 10;

I don't have the slighest idea about how to do it. (I have never
worked with compiler stuff)
Any idea what options I have?

Thanks.
[You could practically do that with grep, with a prepass to get rid
of the comments. -John]

Report this thread to moderator Post Follow-up to this message
Old Post
Zombie
08-25-04 08:59 PM


Re: detect hardcodings in C/C++
natkhatbandar@yahoo.com (Zombie) wrote
> Hi,
> I wish to scan C/C++ code and detect any hard coded statements in it,
> like the '1000' in:
> char str[1000];
>
> or the '10' in:
> int i = 10;

> [You could practically do that with grep, with a prepass to get rid
> of the comments. -John]

If you want to extract integer constants from your C/C++ file, you can
type this piece of code, written in CodeWorker, and save it in
"integers.cwp" :
integers ::=
// ignore C++-like comments between BNF symbols,
// so that it doesn't read integers into comments
#ignore(C++)
[
// jump to the next integer, and consume it
->[
#readInteger:iValue
// trace the integer on the console
=> traceLine(iValue);
|
// if a string is encountered, consume it
// to not take into account the integers,
// which are perhaps into
#readCString
]
]* // search again
;

Then, download CodeWorker at "http://www.codeworker.org" and type the
command line:
codeworker -parsebnf integers.cwp <your-C-file.c>

If you have more than one file to process, write the following lines
in the file "iterateSources.cws":
forfile i in "*.c" {
parseAsBNF("integers.cwp", project, i);
}

and execute :
codeworker iterateSources.cws

As CodeWorker is also a source code generator, you can choose to save
the integers in a file, following a template-based script, instead of
writing them on the console. You can also write the filename
(getInputFilename()), the line (countInputLines()) and column
(countInputCols()) where they were located.

Report this thread to moderator Post Follow-up to this message
Old Post
Cedric LEMAIRE
09-03-04 09:03 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Compilers archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:52 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.