I'm using C++ builder XE under Windows 7 pro.
I'm currently stepping through a function and want to inspect the value of some of my variables. There's a character array I've got, local to a function.
char result[80];
When I try to inspect this (with the code paused inside this function), a message pops up :
Error inspecting 'result': F1007 Irreducible expression tree
If I try to add a watch to this variable, it says "???".
Any ideas what could cause this, and what it could mean in this context ?
According to the documentation:
F1007 Irreducible expression tree (C++)
An expression on the indicated line of the source file caused the code generator to be unable to generate code. Avoid using the expression. Notify Embarcadero if an expression consistently reproduces this error.
You are likely encountering a codegen bug and should file a Quality Central ticket to Embarcadero for review.
Related
XCode Version 6.3.2 (6D2105)
The variable I'm attempting to display is of type boost::posix_time::ptime but my question applies to any C/C++ type. The documentation for boost::posix_time::ptime specifies that the date part of the time (year, month, day) is retrieved by the date() method, and the fractional part of the time (hours, minutes, seconds) is returned by the time_of_day() method. So right-clicking on the variable in the list while the debugger is active allows me to set the summary format, and to just display the year part of the date should be something like {$VAR.date().year()}. Ideally I would like to print 2015/6/11 3:20:29 in the summary next to the variable in the debugger view, but for now I'm just trying to display the year part.
However, 'Summary Unavailable' is displayed, and the output window prints:
error: call to a function 'boost::date_time::date<boost::gregorian::date, boost::gregorian::gregorian_calendar, boost::gregorian::date_duration>::year() const' ('_ZNK5boost9date_time4dateINS_9gregorian4dateENS2_18gregorian_calendarENS2_13date_durationEE4yearEv') that is not present in the target
The documentation (PDF format) states that summary format expressions can contain function and method calls, but the example given is for Objective C, not C++. This is in the main section Writing Data Formatters and sub-section Expressions, including function or method calls
The error you are getting indicates that you are trying to call a function that doesn't exist in the program you are running. With C++ that can happen if the function was only ever present inlined. The debugger doesn't currently know how to construct callable versions of functions from headers, and we certainly can't call an inlined version of it. You can verify this by running nm on your binary and see if there really is a symbol like that around.
The other possibility is there is such a function, but it differs by const or that the type of one of the arguments is slightly different from the one the expression parser guessed it would be, so we are looking for a slightly different mangled name, and not finding it. If a plausible looking candidate does indeed show up when you do nm on the binary and we aren't calling it, please file a bug with the bug reporter at:
http://lldb.llvm.org
so somebody can take a look at it.
I've got a TypeScript script that has to interact with a third-party vendor that uses global functions as callbacks (you can't pass in a callback). For instance, to "listen" for a result from their "API", you define the function SetElqContent. E.g.,
window.SetElqContent = function(){/* handle result */};
When the TypeScript compiler sees this line, it complains that The property 'SetElqContent' does not exist on value of type 'Window'.
I thought I could get around this by simply casting to type "any". Actually, this isn't type casting but type assertion, but I think of it as casting, although I understand it's not quite the same. So, I tried:
(<any>window).SetElqContent = function(){/* handle result */};;
To m y surprise, this results in Syntax error, and the line number and column points to the < character in the <any> cast. I tried a few other variants, and I get Syntax error on the initial < of the cast no matter what kind of cast I was doing:
var windowAny = <any>window;
var docElement = <HTMLElement>window.document;
What is it about my type assertions that is invalid syntax?
I'm using Visual Studio 2013 with Update 2, which has a "compile on save" feature for TypeScript files. That's how I'm compiling my .ts files, and it's from in Visual Studio where the Syntax error message is emitted.
UPDATE: Apparently this is related to Visual Studio. When I use the standalone tsc compiler to compile the same file, it emits no errors or warnings.
Apparently my syntax is correct but there is a bug in the Visual Studio tooling. I can't provide exact reproduce steps, and in fact, deleting everything in the .ts file, saving, then restoring the code (via ctrl-z) and resaving caused the "syntax error" warning to disappear.
If I can determine any more specifics about what causes this issue to manifest, I'll report back.
Best way is to create a type definitions file for it
If the library name is eloqua.js, you create a eloqua.d.ts file and refer to it in your .js file like
/// < reference path="../typings/eloqua.d.ts" />
There are many type definition files online available at definitelyTyped website.
https://github.com/borisyankov/DefinitelyTyped
You can contribute yours to there as well.
If you extend the Window interface definition, you'll remove the error:
interface Window {
SetElqContent: Function;
}
window.SetElqContent = function(){/* handle result */};
Here is how you can do the assertion properly:
function SetElqContent(){/* handle result */};
// FINE
(<any>window).SetElqContent = SetElqContent;
or
// FINE
(<any>window).SetElqContent = function SetElqContent(){/* handle result */};
However you should avoid asserting and just do what Steve Fenton recommends as it is more discoverable
Update
Demo in VS:
does anyone know a cause for random overflow errors in vb6?
I have to customize a legacy application written in VB6 and lately overflow errors have started to occur all over the place. Sometimes in functions which have not been touched in years!
The error always happens when trying to assign something to a variable of type Double.
The reason for those errors is probably not the code that throws the error but something else. But I dont know what to look for. The most confusing example of a function failing with an overflow error was the following code:
Dim test As Double
test = 0#
How can that possibly throw an overflow error?
I tried enabling some compiler optimizations, like not checking for floating point calculation errors, and some more. This has "solved" some of the problems, but others remain.
VB6 will run things in such a way where if something external signals a floating-point error flag, it'll not be reported until the next floating-point operation is performed within your own code.
Under most circumstances, this is likely caused by some DLL that is performing floating-point operation. If you have any control over these external DLLs, then my suggestion is to put this line at the end of the functions called by your application:
_clearfp();
This function is documented here: http://msdn.microsoft.com/en-us/library/49bs2z07.aspx
If you do not have much control, you can get around this by making your own function called from a DLL that calls that function. Or a simple hack with only using VB6 is:
Public Sub ClearFP()
On Error Resume Next
Dim d as Double
d = 0#
End Sub
Which you can call after any DLL calls that you believe is the culprit.
A trick to isolating which function did it originally, is simply look at the calls before the error appears. Alternatively, a more complicated solution, is to compile your application and run it through a debugger that can break on floating-point exceptions.
In VB6 the hash (#) symbol can mean many things:
Used in file names
used with dates ususlly when applied to DBs
To treat Numbers as Doubles
To compile constants or sections of code if a condition is true
I'm sure there are more.
It may depend on the compiler.
My suggestion would be to try:
Dim test As Double
test = CDbl(0)
to see if that resolves the issue.
I tried some suggestions found online but it does not work for me. Im using Visual Studio 2010. Basically I typed loc(kcs(1,4)) (thats my variable) and I obtained 157510036. Its hex is 9636994. So then I typed (INTEGER*)0x9636994 but on the watch window under the "value"column it says "undefined variable INTEGER". I trid lowercase integer or real and same answer. Any suggestion?
I typed (INTEGER*)0x9636994 but on the watch window under the "value"column it says "undefined variable INTEGER".
According to Restrictions on Native C++ Expressions:
Type Casting
If you cast to a type, the type must be known to the debugger. You must have another object of that type in your program. Types created using typedef statements are not supported.
Try using the underlying type. So, for example, if INTEGER is actually an int you would try to watch (int *)0x9636994.
This also assumes that the variable is fixed at 0x9636994 (basically that you're not trying to refer to something transient on the stack).
Is it possible to get Visual Studio to do mathematical expression evaluation/reduction?
For example if I type '-0.005 + -0.345' how do I get Visual Studio to reduce that (i.e. replace it with the reduction)? Do I have to write a macro? If so, are there any pre-existing macros to do this type of expression reduction?
Just to be clear, I want to be able to highlight an expression and have it replaced with the reduced result. Many are suggesting the immediate window but I fail to see how that will suffice?
Edit I should point out that this is while editing not running or debugging. The immediate window is of little to no use. I also consider this a language neutral question. I would certainly be interested in seeing alternative macros to the one I had posted.
Edit Going Once... Going Twice... (i.e. any other suggestions before I consider accepting my own answer?)
Thank you for the above answers.
There probably are better ways, but here's a quick and dirty macro that does what I need.
References to the System.Data and System.XML namespaces need to be added.
Highlight the expression you want to evaluate and run the macro (it uses the calculated column in the DataTable to evaluate the expression.) It will replace the expression with the reduced result.
Edit - Updated code below. It worked extremely well for reducing a large number of expressions. As pointed out by others there is the immediate window but this will not work for editing purposes. This macro is a language independent solution for basic expressions "(), +, -, *, /".
Sub Eval()
Dim ts As EnvDTE.TextSelection = DTE.ActiveDocument.Selection
Using dt As New DataTable()
dt.Columns.Add("Expression", GetType(Double), ts.Text)
dt.Rows.Add(dt.NewRow)
ts.Text = CDbl(dt.Rows(0).Item("Expression"))
End Using
End Sub
Visual Studio by default will not do any mathematical expression evaluation / reduction. I'm not sure if you can get support for that via items like ReSharper, but if it is available it will be in an add-in.
Also, it would be helpful to know the language you are working in?
Some languages may be helpful in this area. F# for instance makes it easy to evaluate expressions in the IDE via the interactive window and will display out the result. This could easily be added back into your code but it doesn't appear to be exactly what you're looking for.
Here's an answer: Yes, it is possible using the following steps. (While technically performing what you're asking for, I'm not sure it will be extremely useful. :-)
Set a breakpoint in your program that's likely to get hit when you debug the program.
Then, run your program under the Visual Studio debugger.
When the breakpoint is hit, open the Watch window.
In the Watch window, add a new watch by clicking in the Name column.
Enter your expression '-0.005 + -0.345' (without the quotes) then hit [Enter].
... You should see the Value column get populated with -0.35.
Of course, that isn't in the context of the editor window ... which is, presumably, where you'd want to perform the reduction. So again, not very useful, I imagine. An add-in is the likely way to do that in the editor window.
You could just go to the immediate window and type "?<yourExpression>"