An existing program that is being converted to use Oracle Pro*C is causing problems upon precompilation. It reads a file from the filesystem, parses it, and writes to a couple of database tables.
There's a method with the following definition:
void parse_line(inline)
char *inline;
{
// do stuff
}
When I attempt to make it, I see:
Syntax error at line 162, column 13, file myfile.cp:
Error at line 162, column 13 in file myfile.cp
char *inline;
............1
PCC-S-02201, Encountered the symbol ";" when expecting one of the following:
( * const, volatile, an identifier,
This function declaration is syntactically correct as far as I can tell, so I have to assume that this precompiler error is coming up because of a problem elsewhere.
Short of pasting the entire program in here, does anybody have any suggestions as to a few good places I could start looking?
My pcscfg.cfg looks like this:
sys_include=($ORACLE_HOME/precomp/public,/usr/include,/usr/lib/gcc-lib/x86_64-redhat-linux/3.2.3/include,/usr/lib/gcc/x86_64-redhat-linux/4.1.1/include,/usr/lib64/gcc/x86_64-suse-linux/4.1.2/include,/usr/lib64/gcc/x86_64-suse-linux/4.3/include)
ltype=short
define=__x86_64__
That declaration is invalid since inline is a keyword in C and C++ (and can only be used as a function specifier in C).
Change that variable name to something else, and that should go through if you're compiling as C and not C++. I don't believe that style of function definition syntax is acceptable in C++.
Related
I have a file that contains an arbitrary number of lines of c++ code, each line of which is self-contained (meaning it is valid by itself in the main function). However, I do not know how many, if any, of the lines will have valid c++ syntax. An example file might be
int length, width; // This one is fine
template <class T className {}; // Throws a syntax error
What I want to do is write to a second file all the lines that have valid syntax. Currently, I've written a program in python that reads each line, places it into the following form
int main() {
// Line goes here
return 0;
}
and attempts to compile it, returning True if the compilation succeeds and False if it doesn't, which I then use to determine which lines to write to the output file. For example, the first line would generate a file containing
int main() {
int length, width;
return 0;
}
which would compile fine and return True to the python program. However, I'm curious if there is any sort of try-catch syntax that works with the compiler so I could put each line of the file in a try-catch block and write it to the output if no exception is thrown, or if there's a way I can tell the compiler to ignore syntax errors.
Edit: I've been asked for details about why I would need to do this, and I'll be the first to admit it's a strange question. The reason I'm doing this is because I have another program (of which I don't know all the implementation details) that writes a large number of lines to a file, each of which should be able to stand alone. I also know that this program will almost certainly write lines that have syntax errors. What I'm trying to do is write a program that will remove any invalid lines so that the resulting file can compile without error. What I have in my python program right now works, but I'm trying to figure out if there is a simpler way to do it.
Edit 2: Though I think I've got my answer - that I can't really play try-catch with the compiler, and that's good enough. Thanks everyone!
Individual lines of code that are syntactically correct in the context of a C++ source file are not necessarily syntactically correct by themselves.
For example this:
int length, width;
happens to be valid either as part of a main function or by itself -- but it has a different meaning (by itself it defines length and width as static objects).
This:
}
is valid in context, but not by itself.
There is typically no way for a compiler to ignore syntax errors. Once a syntax error has been encountered, the compiler has no way to interpret the rest of the code.
When you're reading English text, adfasff iyufoyur; ^^$(( -- but you can usually recover and recognize valid syntax after an error. Compilers for programming languages aren't designed to perform that kind of recovery; probably the nature of C++'s syntax would make it more difficult, and there's just not enough demand to make it worth doing.
I'm not sure what your criterion for a single line of code being "correct" is. One possibility might be to write the line of code to a file, contained in a definition of main:
int main() {
// insert arbitrary line here
}
and then compile the resulting source file. I'm not sure that I can see how that would be particularly useful, but it's about the closest I can come to what you're asking for.
What do you mean by "each line is self-contained"? If the syntax of a line of C++ code is valid may depend largely on the code before or after that line. A given line of code might be valid within a function, but not outside a function body. So, as long as you can't define what you mean by "self-contained" it is hard to solve your problem.
I tried to run the makefile on https://github.com/nasadi/Zambezi. It shows an error like:-- "file included from src/driver/buildContiguous.c:7:0: src/shared/dictionary/Dictionary.h: In function ‘readDictionary’: src/shared/dictionary/Dictionary.h:132:8: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result] fread(&id, sizeof(int), 1, fp);" . Can anyone help me to run the program.Do i need to install any packages.I am new to c programming.
In fact, this is not an error, it is a warning. When compiler emits a warning, it means that code is syntactically correct but may potentially contain logic error.
In your case compiler says that return value of the fread function is not examined. Such ignorance can lead to a situation, where, for e.g., end of file is encountered, but the program is unaware of it and continues execution. Therefore, variable read from file have wrong value, and wrong (invalid) values may cause program crash later on.
Summarizing, if there are no other errors, then your program is successfully compiled and can be run.
I have a C header with this function:
OSStatus MyGetDataFromExtAudioRef(ExtAudioFileRef ext_file_ref, const AudioStreamBasicDescription* restrict output_format, ALsizei max_buffer_size, void** data_buffer, ALsizei* data_buffer_size, ALenum* al_format, ALsizei* sample_rate);
I can #include this header in an Objective-C file and compile fine.
If I change that same Objective-C file to a .mm suffix rather than .m and verify that it is now identified as Objective-C++ source, I get a compiler error that says Expected ')' on the line above. While not clear, it seems to be placing the source of the error on the word output_format parameter.
There is nothing in the above function that appears to be bad syntax, with regards to parenthesis, and I can't understand why this one change should make any difference.
Does anything jump out at anyone here?
Simple, the restrict keyword isn't part of the C++ standard, so the C++ compiler (that is used to compile Objective-C++ code) doesn't recognize it.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Weird MSC 8.0 error: “The value of ESP was not properly saved across a function call…”
I have an OBJ file for which I don't have any soure code. I have used it in another project without any problems. Now I am trying to use it in another project. Here is the way I declare it:
extern "C" bool FileCompare(char* file1, char* file2);
I use it in a function like this:
void myFunction() {
//some code
FileCompare(file1, file2); // file1 and 2 are char arrays
}
Then in my main code I call myFunction:
int main() {
... some code
myFunction()
}
When myFunction returns I get "The value of ESP was not properly saved across a function call." in Visual Studio 2010 debugger. However, I know for a fact that FileCompares (the function in the obj file) does its job. When I comment it out everything works fine. I have used this OBJ file in the past without any problems. Considering I don't have the source of the obj file, is there anything I can do to try to "patch" this problem?
Thank you very much
More details: I suspect that the code uses CALL without RET (its written in assembly).
EDIT: I don't know if what I say makes sense the way things work, but since the function corrupts the esp is there anyway to save it and restore it after the function returns?
This is either due to a bug in FileCompare() or mismatched calling conventions between the declaration and implementation of myFunction() and/or FileCompare().
You might be able to fix the problem with an appropriate specifier (like maybe __cdecl) on the prototype for FileCompare(). Or you might need to create an assembly language wrapper for the FileCompare() function that fixes things up (since you say that you no longer have the source for FileCompare()).
Figuring out exactly what's wrong without FileCompare() source might require stepping thorough the assembly in a debugger.
I run into a similar problem once when I was compiling one project against old header file that differed from the latest by one missing virtual function.
I'm consistently running into an internal compiler error while attempting to switch from MSVC6 to MSVC 2008. After much work commenting out different parts of the program, I've traced the error to two lines of code in two different CPP files. Both of these CPP files compile successfully, yet somehow have an effect on whether or not the error manifests in other files.
Both of those lines involve instantianting several complex, nested templates. They also appear to be the only places in the app that use an abstract class as one of the template parameters. That said, I'm far from certain that the issue involves either abstract classes or templates, it's just the most obvious thing I've noticed. I can't even be sure that these lines are significant at all. Here's what they look like, though:
m_phDSAttributes = new SObjDict<RWCString, SIDataSource>(&RWCString::hash);
So we've got SObjDict, a templatized dictionary class, SIDataSource, an abstract interface, and the parameter is a pointer to a static member function of RWCString.
I've been playing around with the code some, and I can occasionally get the error to move from one CPP file to another (for instance, I changed a bunch of template declarations from using class to typename), but I can't find any rhyme or reason to it.
I'm at a loss as to how to debug this issue further. The exact error output by the compiler (with the name of my source file changed) is below. There is no mention of it anywhere on the internet. I'm pretty desperate for any advice on how to proceed. I don't expect someone to say "oh, you just need to do XYZ", but a pointer on how to debug this sort of issue would be greatly appreciated.
1>d:\Dev\webapi.cpp : fatal error C1001: An internal error has occurred in the compiler.
1>(compiler file 'f:\dd\vctools\compiler\utc\src\p2\p2symtab.c', line 5905)
The trick seems to be disabling precompiled headers. I have no idea why that solves the problem, and it's very unfortunate since my build time for the affected project has gone from less than 30 secs to nearly 5 minutes, but at least I can progress forward.
It's a reasonable bet to assume that p2symtab.c is (part of) the symbol table code. This would immediately explain how the upgrade caused it; this code has been rewritten. (Remember the 255 character length warnings of VC6?)
In this case, there is no new entry in the symbol table, so it's likely a lookup in the symbol table failing spectactularly. It would be interesting to see if the context in which th name lookup happens affects the result. For instance, what happens if you change the code to
typedef SObjDict<RWCString, SIDataSource> SObjDict_RWCString_SIDataSource;
m_phDSAttributes = new SObjDict_RWCString_SIDataSource(&RWCString::hash);
This will force another symbol table entry to be created, for SObjDict_RWCString_SIDataSource. This entry is sort of a symbolic link to the template instantiation. The new name can (and must) be looked up on its own.
Start breaking it down into smaller parts. My first guess is the pointer to the static function is going to be the problem. Can you make a dummy non-template class with the same parameter in the constructor? Does it compile if you don't use an abstract class in the template?
Looks like I'm sending you in the wrong direction, the following compiles fine in 2008:
class thing {
public:
static void hash( short sht ) {
}
void hash( long lng ) {
}
};
class thing2 {
public:
thing2( void (short ) ){}
};
int _tmain(int argc, _TCHAR* argv[])
{
thing2* t = new thing2( &thing::hash );
delete t;
return 0;
}
The principle remains though, remove/replace complex elements until you have code that compiles and you'll know what is causing the problem.
fatal error C1001: An internal error has occurred in the compiler.
1>(compiler file 'f:\dd\vctools\compiler\utc\src\p2\p2symtab.c
i also observed the same error when i try to build my vs 2005 code to vs 2008. but it happen till i have not installed Service pack of VS 2008...
have you installed Service pack... i think this will resolved your issue....
This typically happens with template instantiation. Unfortunately it could be caused by many things, but 99% of the time your code is subtly invoking undefined behavior.