我已经阅读了一个getopt()示例,但它没有显示如何接受整数作为参数选项,就像cvalue在示例的代码中一样:
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int
main (int argc, char **argv)
{
int aflag = 0;
int bflag = 0;
char *cvalue = NULL;
int index;
int c;
opterr = 0;
while ((c = getopt (argc, argv, "abc:")) != -1)
switch (c)
{
case 'a':
aflag = 1;
break;
case 'b':
bflag = 1;
break;
case 'c':
cvalue = optarg;
break;
case '?':
if (optopt == 'c')
fprintf (stderr, "Option -%c requires …Run Code Online (Sandbox Code Playgroud) 我有以下build.xml和build.properties文件:
build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="CoolProducts" basedir="../"
default="dev" description="CoolProducts front-end">
<!-- set default config -->
<property file="build/config/build.properties" />
<target name="dev">
<echo message="{$dir.css}" />
<echo message="{$dir.build}" />
<echo message="{$dir.source}" />
</target>
</project>
Run Code Online (Sandbox Code Playgroud)
build.properties
dir.source = .
dir.css = css
dir.build = build
Run Code Online (Sandbox Code Playgroud)
我希望我的输出是:
css
build
.
Run Code Online (Sandbox Code Playgroud)
但它是:
{$dir.css}
{$dir.build}
{$dir.source}
Run Code Online (Sandbox Code Playgroud)
我配置不正确吗?
我正在尝试将指针传递struct timevals给一个函数,该函数将在C程序中输出两者之间的经过时间.但是,即使我取消引用这些指针,nvcc也会抛出错误"表达式必须具有类类型"(这是一个CUDA程序).以下是main()的相关代码:
struct timeval begin, end;
if (tflag) { HostStartTimer(&begin) };
// CUDA Kernel execution
if (tflag) { HostStopTimer(&begin, &end); }
Run Code Online (Sandbox Code Playgroud)
以及HostStopTimer()的函数定义:
void HostStopTimer(struct timeval *begin, stuct timeval *end) {
long elapsed;
gettimeofday(end, NULL);
elapsed = ((*end.tv_sec - *begin.tv_sec)*1000000 + *end.tv_usec - *begin.tv_usec);
printf("Host elapsed time: %ldus\n", elapsed);
}
Run Code Online (Sandbox Code Playgroud)
导致错误的行是赋值elapsed.我没有太多在C中使用结构的经验,更不用说将结构传递给函数的结构,所以我不确定导致错误的是什么.
我不确定这个setter函数声明有什么问题,因为同一个类中的其他setter函数具有相同的语法,并且它们不会导致错误.我认为在此声明之前可能是行中的语法错误,但我也检查过这些并且似乎无法找到原因.这是代码:
#import <Foundation/Foundation.h>
@interface PolygonShape : NSObject {
}
@property int numberOfSides;
@property int minimumNumberOfSides;
@property int maximumNumberOfSides;
@property (readonly) float angleInDegrees;
@property (readonly) float angleInRadians;
@property (readonly) NSString *name;
-(void)setNumberOfSides:(int); // Error: expected idenitifier before ';' token
-(void)setMinimumNumberOfSides:(int);
-(void)setMaximumNumberOfSides:(int);
-(id)initWithNumberOfSides:(int)sides minimumNumberOfSides:(int)min maximumNumberOfSides:(int)max;
-(id)init;
-(float)angleInDegrees;
-(float)angleInRadians;
-(NSString*)name;
-(NSString*)description;
@end
Run Code Online (Sandbox Code Playgroud)
我也认为这可能是因为我在实现中合成了函数,但我也在使用setMinimumNumberOfSides和setMaximumNumberOfSides.如果您需要我的实现中的代码来帮助解决这个问题,请发表评论,我很乐意发布它.