Stringify Endpoint for Xcode LLVM Processor Macros - xcode

In the "Apple LLVM 7.0 - Preprocessing" section under the "Build Settings" tab, I've defined a Preprocessor Macros as:
STR(arg)=#arg
HUBNAME=STR("myhub")
HUBLISTENACCESS=STR("Endpoint=sb://abc-xyz.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=JKLMNOP=")
In my code, I'm trying to refer to the value of HUBLISTENACCESS as a string:
SBNotificationHub* hub = [[SBNotificationHub alloc] initWithConnectionString:#HUBLISTENACCESS notificationHubPath:#HUBNAME];
But I'm getting errors from Xcode for the initialization of "hub":
Expected ';' at end of declaration
Unterminated function-like macro invocation
Unexpected '#' in program
I suspect that the definition of HUBLISTENACCESS in the Preprocessor Macros needs to be properly escaped but I've tried a few things and can't seem to get it right. Can somebody help me understand what I'm doing wrong?

There's one very obvious reason why you were trying to do failed: you use // in the HUBLISTENACCESS. As in C, things after // were commented out so in the aspect of the compiler, the last line of yours is actually:
HUBLISTENACCESS=STR("Endpoint=sb:
To test it, just remove one slash and it will work again. What you were doing like trying to define things as such:
#define FOO //
which I don't think it's possible. I honestly have no idea how you can do that within the Build Settings, but there are other ways to do it globally via a PCH file (prefix header).
A simple line within the PCH will will save all those troubles:
#define HUBLISTENACCESS #"Endpoint=sb://abc-xyz.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=JKLMNOP="
Then use it as below: (no more # needed!)
NSLog(#"%#", HUBLISTENACCESS);

Related

How to get gcc to compile 16-bit unicode strings

So I'm trying to compile this project : https://github.com/dmitrystu/libusb_stm32 with Segger Embedded studio which uses gcc. The process is choking on this error :
pasting formed 'u"Open source USB stack for STM32"', an invalid preprocessing token
which is caused by this line :
static const struct usb_string_descriptor manuf_desc_en = USB_STRING_DESC("Open source USB stack for STM32");
So USB_STRING_DESC is a macro :
#define USB_STRING_DESC(s) {.bLength = sizeof(CAT(u,s)),.bDescriptorType = USB_DTYPE_STRING,.wString = {CAT(u,s)}}
And CAT is a macro CAT(x,y) x##y. The intent must be to convert a string of type 8-bit char into a 16-bit Unicode type but the compiler doesn't like it. Is there some #include or compiler setting that may be missing that I have to add here? Clearly the author of this code expects it to work so there must be some fault in my setup.
Also I'm not clear on how the sizeof() operation is supposed to work here. As I understand it there is no way to get the length of a string at compile time so that operation will always return the size of a pointer.
In response to Keith's question, the gcc version is 4.2.1. Poking around the compiler settings the default option is the C99 standard, when I changed it to C11 everything compiled just fine. Thanks!

Debugging Alpha BASIC for OpenVMS

I am trying to take over some projects involving DEC BASIC, A.K.A. VAX BASIC, A.K.A. Alpha BASIC. I am really hoping to run into someone with experience here. I have been through the user manual for VAX/Alpha BASIC through and though but I can't figure out how to debug shareable code.
I can create, compile and link shareable code, I can debug the code that references the shareable code, but I can't debug the shareable code. Any help would be greatly appreciated.
The commands I am using to compile and link are:
$ BASIC/DEBUG/NOOPTIMIZE COMPARE_DATES_TEST.BAS,COMPARE_DATES.BAS
$ LINK/SHAREABLE/DEBUG COMPARE_DATES.OBJ,COMPARE_DATES_SUB/OPT
$ LINK/DEBUG COMPARE_DATES_TEST,COMPARE_DATES_MAIN/OPT
$ RUN COMPARE_DATES_TEST
The contents of the two option files are:
$ type COMPARE_DATES_SUB.OPT
! COMPARE_DATES_SUB.OPT
SYMBOL_VECTOR=(COMPARE_DATES=PROCEDURE)
$ type COMPARE_DATES_MAIN.OPT
! COMPARE_DATES_MAIN.OPT
COMPARE_DATES/SHAREABLE
My shareable code has a bug, but I don't know where, the debugger reports:
— SRC: module COMPARE_DATES_TEST$MAIN -scroll-source————————————————————————————
1: EXTERNAL INTEGER FUNCTION COMPARE_DATES(STRING,STRING)
2: DECLARE STRING A$, B$
3: A$ = "01-APR-18"
4: B$ = "15-MAY-2017"
5:
-> 6: PRINT COMPARE_DATES(A$, B$)
7: END
— OUT -output———————————————————————————————————————————————————————————————————
stepped to COMPARE_DATES_TEST$MAIN\COMPARE_DATES_TEST$MAIN\%LINE 3
stepped to COMPARE_DATES_TEST$MAIN\COMPARE_DATES_TEST$MAIN\%LINE 4
stepped to COMPARE_DATES_TEST$MAIN\COMPARE_DATES_TEST$MAIN\%LINE 6
%BAS-F-SUBOUTRAN, Subscript out of range
-BAS-I-FROFUN, In external function COMPARE_DATES
-BAS-I-FROMOD, In module COMPARE_DATES_TEST
break on unhandled exception preceding 18446744071563830960
— PROMPT -error-program-prompt——————————————————————————————————————————————————
%DEBUG-I-SOURCESCOPE, source lines not available for %PC in scope number 0
Displaying source for 6\%PC
DBG>
Too long for a comment: You compiled with /NOOPTIMIZE, so I would have expected that a STEP/INTO when at line 6, PRINT COMPARE_DATES(A$, B$), would have stepped to COMPARE_DATES in your shareable image. I don't know why that's not the case, here. The debugger is right, you don't have the sources for DEC$BASRTL. Your shareable image is not installed, it is in your address space. It seems PRINT has problems with the passed argument. I would try a SET IMAGE COMPARE_DATES; SET MODULE/ALL; SET BREAK COMPARE_DATES at the initial debugger prompt. That makes all debug symbols of the shareable image known and sets a breakpoint in your function. And then a GO should get you into your function. (I noticed, that you have the same names for the function, the source module and the shareable image. This shouldn't be a problem.)

Is it possible to run extra lines of code during debugging

I want to execute extra lines of code during debugging in Visual Studio 2012.
Is it possible to make it.
One application would be to execute some WRITE(,) statements, or evaluate some expressions.
If you're using F77 with the Intel Compiler, have a look at the /D-lines option. You can write code like
if (x.gt.10) then
x = 0
D print *, 'x reset'
end if
It will only compile the lines with D in column 1 if the /D-lines option is present, otherwise it is treated as a comment. I've only ever used this on F77. I don't know if it works on F90 etc.
Reference http://software.intel.com/sites/products/documentation/doclib/stdxe/2013/composerxe/compiler/fortran-lin/GUID-E356B0E3-F847-40A9-A932-77B4D8EEF53B.htm
The Intel compiler also supports preprocessing. You could use either
the C type macros with #if etc http://software.intel.com/sites/products/documentation/doclib/stdxe/2013/composerxe/compiler/fortran-mac/GUID-4A598AC5-1C5F-48F2-BA42-DA8F38D46CB3.htm
the original Microsoft/DEC macros with !DEC$ http://software.intel.com/sites/products/documentation/doclib/stdxe/2013/composerxe/compiler/fortran-mac/GUID-0E1D6C34-2565-4331-864F-5970EF452E27.htm
If you're using Silverfrost, have a look at the CIF-CELSE-CENDIF /VPARAM /SPARAM options.
You can use the #if to do this within Visual Studio.
#if DEBUG
Console.WriteLine("Debug version");
#endif
http://msdn.microsoft.com/en-us/library/4y6tbswk(v=vs.110).aspx

How to disable the "local declaration of 'foo' hides instance variable" warning?

I understand what the warning says. This is exactly how scoping rules work. I appreciate that some people want a nanny. I don't. How can I disable this warning?
You can't disable this warning in the current version of XCode. There is no build setting for it, nor does it have a warning ID which you could use to pass a flag to the compiler to tell it to quit whining.
For future reference, you can find that warning ID by going to the Log Navigator, clicking on the most recent build where the warning appeared, drilling down into the log to find the point where the 'compile' task shows up with an exclamation mark and click the 'more detail' button, which looks like a gray callout with 5 horizontal lines. You'll see the warnings/errors listed in detail, and if there was a warning ID it would appear on the line detailing the warning in yellow. At least, thats what I've been told by one of the Compiler Engineers at Apple. I have yet to see a warning that I actually want to disable have an ID appear in the log.
File a bugreport with Apple, tell them you want more options to disable warnings in XCode and list this one specifically.
In Xcode 4.4 this can be disabled by going to the build setting "Other Warning Flags" and setting the value "-Wno-shadow-ivar"
The warning name you're looking for is "shadow-ivar". It appears in the log in Xcode 4.3 as something like warning: local declaration of 'foo' hides instance variable [-Wshadow-ivar].
I still don't see it in the project's Build Settings list, but #pragma clang diagnostic ignored "-Wshadow-ivar" will take care of it in one file at a time. I actually like to turn it off for particular functions and then turn it on again. That way it ceases to nag me where I've decided I don't care but will warn me again in new code.
NSString *foo;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wshadow-ivar"
- (void)myFunctionWithShadow_ivarWarningsIgnored {
NSString *foo = #"...";
NSLog(#"This shouldn't get a warning %#", foo);
}
#pragma clang diagnostic pop
- (void)myFunctionWithShadow_ivarWarningsNotIgnored {
NSString *foo = #"...";
NSLog(#"and this should %#", foo);
}
Good Luck! :)
Update for Xcode 8.3 - Bug in compiler yields "Declaration shadows a local variable" in some instances when it intentional... and the nanny panics.
For example in Objective C:
Given
typedef BOOL ( ^BoolBoolBlock ) ( BOOL );
And the nature of Apple Blocks will make any variable declared in the immediate outer scope to a Block, a global to the block (pseudo globals). This results in the warnings (and errors if warnings == errors in your settings) on the line BOOL theResult = false;:
- (BoolBoolBlock) boolBoolBlock {
BoolBoolBlock theResult = nil;
theResult = ^BOOL ( unused BOOL is ) {
BOOL theResult = false; // hides (shadows) the outer theResult (a good thing)
/*
call back code goes here,
all variables local in scope to this method are global to the block so be careful
*/
return theResult;
};
return theResult;
}
The nanny sees BoolBoolBlock theResult = nil; getting shadow-blocked by BOOL theResult = false; which is actually intentional for two reasons in this case:
by convention in my code ALL return values are theResult no matter what
is a positive side effects because I am morally opposed to globals.
In other words this entire construct is setup to block the pseudo global mechanisms of Apple Blocks and put structure on that chaos. Blocking the method's "theResult" from use in the block that the method returns is a good thing ... yet the nanny has a hissy fit.
To calm the nanny down (get rid of warnings or possibly errors if you have the discipline to set warnings as errors), you simply make this setting change in your Project File -> Build Settings -> filter on "Other" -> Hidden Local Variables -> change to "No" ... or visually:

Xcode 3.2 Debug: Seeing whats in an array?

Whilst debugging in Xcode_3.1.2 I am pretty sure I could see the contents of my NSString arrays. However after upgrading to 3.2 I only see the following ...
I know I can print the object in (gdb) using "po planetArray" or simply click in the debugger and "print description to console" I am just curious, as I am sure it worked prior to upgrading. Anyone know anything about this?
cheers gary
edit: data formatters is on and it shows what you see above ...
This is because GDB acts as if the variable you are viewing is out of scope while it really just is confused about what each part function or method call of the data formatter is returning (the data formatter is the "{(unichar *)Xcode_CFStringSummary($VAR, $ID)}:s" part you are seeing.
When you are debugging and you are in a method where you know a local variable must be in scope right now, open the debugger window and the area where you can see "Variable", "Value" and "Summary" column titles double click the "Summary" row entry for the variable you are interested in and enter the following (for array types like NSArray or NSCFArray):
"{(int)[$VAR count]} objects {(NSString *)[(NSArray *)$VAR description]}:s"
then press return. You have now overwritten the default data formatter provided by Xcode's GDB extension (to be found in various plists at "/Developer/Library/Xcode/CustomDataViews/") with your own data formatter string.
Your own overrides are saved at "~/Library/Application Support/Developer/Shared/Xcode/CustomDataViews/CustomDataViews.plist" and if you want to have the Apple default data formatter back just double click the row for a variable of the same type and delete whatever is there.
The nitty-gritty details: In the custom expression above the "{}" construct tells GDB to execute a command (as if you where executing it from GDB's debugger command line, which means the same restrictions apply: you need to specify the return type in cast parens in front of every function or method which returns something). The ":s" behind the closing curly brace tells Xcode and GDB to reference the "Summary" column. Also valid would be ":v" which references the "Value" column which most of the time is just the pointer value. Everything that is outside of the curly braces is shown verbatim.
Unfortuntely curly braces can't be nested which invalidates ternary operator conditionals.
So with the above data formatter you should see the following for an empty NSArray:
"0 objects (\n)"
If you want to write your own data formatters as GDB extensions (equivalent to specifying a function akin to Xcode_CFStringSummary above) you can do so. Take a look at the following header: "/Developer/Applications/Xcode.app/Contents/PlugIns/GDBMIDebugging.xcplugin/Contents/Headers/DataFormatterPlugin.h"
it will tell you all you need to know. But it can be hard to get it right. It might be easier and less error prone to just define another method on your class and call that from the data formatter string instead of "description".
In the Run > Variables View menu in Xcode, is "Use Data Formatters" enabled?
I am not sure if this helps but if you select the array value to wish to see in the debugger window and the go to the Menu : Run > Variables View > View Variable As
you can change it from "NSCFString *" to "NSString *". You then see the value so "Planet_1" for example.
Cheers,
Kevin

Resources