对于类似以下内容的定义行为是什么?
#include <stdio.h>
typedef enum {
ENUM_VAL_1 = 1,
ENUM_VAL_2 = 2
} TEST_ENUM;
int main() {
TEST_ENUM testVar1 = ENUM_VAL_1;
TEST_ENUM ENUM_VAL_1 = ENUM_VAL_1;
TEST_ENUM testVar2 = ENUM_VAL_1;
printf("ENUM_VAL_1 = %u\n",ENUM_VAL_1);
printf("testVar1 = %u\n",testVar1);
printf("testVar2 = %u\n",testVar2);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
从我对GCC和MSVC编译器的测试来看,这样做的行为是testVar1将被设置为等于枚举值"ENUM_VAL_1"或1.然而,下一个语句将尝试将变量ENUM_VAL_1设置为等于其自己的值,当然是当前未初始化并因此是垃圾,而不是将变量ENUM_VAL_1设置为等于枚举值ENUM_VAL_1.然后,当然,testVar2也将获得与变量ENUM_VAL_1相同的垃圾值.
根据C标准定义的行为是什么,还是这种未定义的行为?无论是否定义,我猜这种类型的例子至少是不好的做法,因为它含糊不清.
谢谢!
我试图使用UIWebView显示一些可变大小的内容,我想确定该内容的完整大小,以便我可以调整UIWebView的大小以完全适合内容的大小.
然而,我尝试确定内容的正确高度和宽度并非完全直截了当.以下尝试测试查找尺寸的方法......
- (void)viewDidLoad {
[super viewDidLoad];
self.webView.backgroundColor = [UIColor clearColor];
NSString *content = @"<html><body style='background-color: transparent; width: 300px; height: 500px'><div id='ContentDiv'>Content Here</div></body></html>";
[self.webView loadHTMLString:content baseURL:nil];
debugLog(@"Loading HTML string: %@", content);
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSString *bodyHeight = [self.webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"];
NSString *bodyWidth = [self.webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetWidth"];
NSString *contentHeight = [self.webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('ContentDiv').offsetHeight"];
NSString *contentWidth = [self.webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('ContentDiv').offsetWidth"];
CGSize fittedSize = [self.webView sizeThatFits:CGSizeZero];
debugLog(@"document.body.offsetHeight/Width: {%@, %@}", bodyWidth, bodyHeight);
debugLog(@"document.getElementbyId('ContentDiv').offsetHeight/Width: {%@, %@}", contentWidth, contentHeight);
debugLog(@"sizeThatFits: %@", NSStringFromCGSize(fittedSize));
self.webView.frame = CGRectMake(0,
0,
[contentWidth floatValue], …
Run Code Online (Sandbox Code Playgroud) 我正在使用NSFetchedResultsController来填充UITableView,其结果来自大约1500个实体的中等大小的Core Data存储.结果控制器是相当标准的 - 潜在错误的一些"热点"不适用于此设置.
然而,我的部分结果非常奇怪.例如,请考虑此方法用于设置节标题视图的标题:
- (NSString *)titleForHeaderInSection:(NSInteger)section {
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.resultsController sections] objectAtIndex:section];
return [sectionInfo name]; // <------- Stopped at breakpoint here
}
Run Code Online (Sandbox Code Playgroud)
我使用断点停在指定的行,并使用GDB检查以下内容:
(gdb) po [[self resultsController] sectionNameKeyPath]
reviewDateString
(gdb) print section
$11 = 1
(gdb) print (int) [sectionInfo numberOfObjects]
$12 = 4
(gdb) po [sectionInfo name]
Wednesday, September 8th 2010
(gdb) po [[[sectionInfo objects] objectAtIndex:0] valueForKey:@"reviewDateString"]
Sunday, February 13th 2011
(gdb) po [[[sectionInfo objects] objectAtIndex:1] valueForKey:@"reviewDateString"]
Sunday, February 13th 2011
(gdb) po …
Run Code Online (Sandbox Code Playgroud) 有人可以解释为什么我的匹配表现不同,无论交替是否包含在捕获组中?
这可能是由于Perl的旧版本(遗憾的是我无法控制),还是我误解了什么?我的理解是,括号是某些人的约定,但在这种情况下则不必要.
[~]$ perl -v
This is perl, v5.6.1 built for PA-RISC1.1-thread-multi
(with 1 registered patch, see perl -V for more detail)
Copyright 1987-2001, Larry Wall
Binary build 633 provided by ActiveState Corp. http://www.ActiveState.com
Built 12:17:09 Jun 24 2002
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this …
Run Code Online (Sandbox Code Playgroud)