我希望有一个函数接受不同类型的结构作为参数.所以,由于我没有特定的类型,我必须使用void*.现在的问题是:当我将结构传递给此函数时,如何在函数内访问此结构的已知成员?具体来说,我知道所有结构都有str1作为成员,我想要,例如,打印它.这是一个示例代码:
struct {
char* str1;
float tt1; } var1 = {"This is me", 12};
struct {
char* str1;
int tt2; } var2 = {"This is you", 18};
void printStruct(void* str)
{
printf("\n the structure string is %s", ??);
//can I put something in ?? to print the string?
}
main(....)
{
printStruct(&var1);
printStruct(&var2);
}
Run Code Online (Sandbox Code Playgroud) 我继承了一些python代码,其中包含一个相当神秘的装饰器.此装饰器在整个项目的类中设置属性.问题是,我已将此调试问题跟踪到此装饰器.似乎它"fubars"我试过的所有调试器,并试图加速psyco休息的代码.(似乎psyco和这个装饰师不好玩).我认为最好改变它.
def Property(function):
"""Allow readable properties"""
keys = 'fget', 'fset', 'fdel'
func_locals = {'doc':function.__doc__}
def probeFunc(frame, event, arg):
if event == 'return':
locals = frame.f_locals
func_locals.update(dict((k,locals.get(k)) for k in keys))
sys.settrace(None)
return probeFunc
sys.settrace(probeFunc)
function()
return property(**func_locals)
Run Code Online (Sandbox Code Playgroud)
像这样使用:
class A(object):
@Property
def prop():
def fget(self):
return self.__prop
def fset(self, value):
self.__prop = value
... ect
Run Code Online (Sandbox Code Playgroud)
我得到的错误说问题是因为sys.settrace.(也许这是滥用settrace?)
我的问题:没有 sys.settrace,是否可以实现相同的装饰器.如果不是,我正在进行一些重写.
我想做的事情相当容易.或者你会想.但是,没有什么工作正常.
要求: 使用maven,使用AspectJ编译器编译Java 1.6项目.
注意: 我们的代码无法使用javac进行编译.也就是说,如果未编入方面,则编译失败(因为我们有方面可以软化异常).
<failOnError>false</failOnError>
到编译器插件(感谢
Pascal Thivent)<phase>process-sources</phase>
到aspectj编译器插件(感谢Andrew Swan)有关这些解决方案的更多信息,请参阅答案部分.我认为解决方案#2是更好的方法.
问题(基于以下失败的尝试):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerId>aspectj</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-aspectj</artifactId>
<version>1.8</version>
</dependency>
</dependencies>
</plugin>
Run Code Online (Sandbox Code Playgroud)
这失败并出现错误:
org.codehaus.plexus.compiler.CompilerException: The source version was not recognized: 1.6
无论我使用的是什么版本的plexus编译器(1.8,1.6,1.3等),这都行不通.我实际上阅读了源代码,发现这个编译器不喜欢Java 1.5以上的源代码.
尝试2(失败): 使用附加到编译和测试编译目标的aspectJ-maven-plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.3</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal> …Run Code Online (Sandbox Code Playgroud) HTML是
<tr>
<td><input /></td>
<td><a>ref</a></td>
</tr>
Run Code Online (Sandbox Code Playgroud)
我有
$('a')
从中获得最佳方法是什么<input />?
如果他们在一起<input /><a></a>,我可以使用$('a').sibling('input'),但他们在不同的td
我正试图深入探讨使用Xcode进行单元测试的相当坦率的可怕世界(这似乎是一个错综复杂的过程.)
基本上我有这个测试类,试图测试我的Show.h类
#import <GHUnit/GHUnit.h>
#import "Show.h"
@interface ShowTest : GHTestCase { }
@end
@implementation ShowTest
- (void)testShowCreate
{
Show *s = [[Show alloc] init];
GHAssertNotNil(s,@"Was nil.");
}
@end
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试构建并运行我的测试时,它会因此错误而呻吟: -
未定义的符号:
"_OBJC_CLASS _ $ _ Show",引自:
Run Code Online (Sandbox Code Playgroud)__objc_classrefs__DATA@0 in ShowTest.old:找不到符号
collect2:ld返回1退出状态
现在我假设这是一个链接错误.我尝试按照此处说明中的每一步操作: -
http://github.com/gabriel/gh-unit/blob/master/README.md
这些说明的第2步让我困惑: -
在Target'Test'信息窗口中,常规选项卡:
添加链接库,在Mac OS X 10.5 SDK部分下,选择GHUnit.framework
添加链接库,选择您的项目.
添加直接依赖项,然后选择您的项目.(这将导致您的应用程序或框架在测试目标之前构建.)
当我所有接受它的.dylib,.framework和.o文件时,我应该如何将我的项目添加到链接库列表?
boolean r = false ; int s = 0 ;
while (r == false) ;
{
s = getInt() ;
if (!(s>=0 && s<=2)) System.out.println ("try again not a valid response") ;
else r = true ;
}
Run Code Online (Sandbox Code Playgroud)
即使输入3或123并且循环永不终止,文本也不会显示.这里有什么不对?
我正在使用一些模型,其中许多给定模型的关键属性实际存储在子模型中.
例:
class WikiArticle
has_many :revisions
has_one :current_revision, :class_name => "Revision", :order => "created_at DESC"
end
class Revision
has_one :wiki_article
end
Run Code Online (Sandbox Code Playgroud)
Revision类有很多数据库字段,WikiArticle很少.但是,我经常需要从WikiArticle的上下文访问Revision的字段.最重要的情况可能是创建一篇文章.我一直在这样做,有很多看起来像这样的方法,每个领域一个:
def description
if @description
@description
elsif current_revision
current_revision.description
else
""
end
end
def description=(string)
@description = string
end
Run Code Online (Sandbox Code Playgroud)
然后在我的保存中,我将@description保存到新版本中.
这一切都让我想起了很多attr_accessor,只是看起来我不能让attr_accessor去做我需要的东西.我如何定义一个attr_submodel_accessor,这样我就可以给出字段名称并让它像attr_accessor一样自动创建所有这些方法?
我用过mime_content_type()和文件信息,但我从来没有成功过.我想现在使用PHP的cURL并获取托管在另一个域上的文件的标题,然后提取并确定该类型是否为MP3.(我认为MP3的mime类型是audio/mpeg)
简而言之,我知道,但我不知道如何应用它:)
谢谢
有人知道C++中的好/小方案解释器吗?优选的是<2000 LOC,带有简单的垃圾collectro(压缩或标记和扫描),不需要支持所有的R5RS,只需要if/lambda/set!/ cons/car/cdr的基础知识和一些基本操作.
谢谢!
我正在学习Django,我正在尝试理解项目中的models.py与应用程序的使用.从教程示例中可以看出,我在应用程序中包含了一个模型定义,但是当我将这些知识应用到我自己的现有数据库时,我遇到了困难.
我使用了一个我使用的数据库(当然是一个副本)并使用inspectdb生成了一个django模型的概念模式.我在项目级别做了这个,并假设我可以使用该项目的应用程序中的子模式编写应用程序.
但是通用教程,他们在应用程序的model.py中定义了模型.如果我这样做,我会重复已经在项目级别的模型(或部分模型),这似乎是一个错误和维护问题.
那么,在Django风格中,我如何使用项目模式(或部分模式)而无需在应用程序的models.py中重新定义它?
提前致谢.
java ×2
python ×2
aop ×1
aspectj ×1
c ×1
c++ ×1
curl ×1
debugging ×1
decorator ×1
django ×1
gh-unit ×1
jquery ×1
linker ×1
maven-2 ×1
mime-types ×1
objective-c ×1
php ×1
properties ×1
scheme ×1
structure ×1
unit-testing ×1
void ×1
while-loop ×1
xcode ×1