代码运行完美,直到我将Xcode更新为v9.0;它不再编译,因为Apple在SimplePing.h提供的文件SimplePing.h中存在错误
C++ requires a type specifIEr for all declarations
在SimplePing.h中的每一行上生成错误
check_compile_time(sizeof(IPheader) == 20);check_compile_time(offsetof(IPheader,versionAndheaderLength) == 0);check_compile_time(offsetof(IPheader,differentiatedServices) == 1);check_compile_time(offsetof(IPheader,totalLength) == 2);check_compile_time(offsetof(IPheader,IDentification) == 4);check_compile_time(offsetof(IPheader,flagsAndFragmentOffset) == 6);check_compile_time(offsetof(IPheader,timetolive) == 8);check_compile_time(offsetof(IPheader,protocol) == 9);check_compile_time(offsetof(IPheader,headerChecksum) == 10);check_compile_time(offsetof(IPheader,sourceAddress) == 12);check_compile_time(offsetof(IPheader,destinationAddress) == 16);
SimplePing.h类包括以下类
#include <AssertMacros.h> // for __Check_Compile_Time
其中check_compile_time的代码定义如下:
#ifndef __Check_Compile_Time #ifdef __GNUC__ #define __Check_Compile_Time( expr ) \ extern int compile_time_assert_Failed[ ( expr ) ? 1 : -1 ] __attribute__( ( unused ) ) #else #define __Check_Compile_Time( expr ) \ extern int compile_time_assert_Failed[ ( expr ) ? 1 : -1 ] #endif#endif
第一个问题:我该如何解决这个问题?
第二个问题:我似乎无法修改AssertMacros.h文件,它被锁定..我应该解锁并修复它吗?或者我还能做些什么来解决这个问题?
要解决此问题,请使用__Check_Compile_Time更新check_compile_time的所有实例
所以Apple的SimplePing.h类的更新代码应如下:
#import <Foundation/Foundation.h>#if TARGET_OS_EMbedDED || TARGET_IPHONE_SIMulATOR #import <CFNetwork/CFNetwork.h>#else #import <CoreServices/CoreServices.h>#endif#include <AssertMacros.h>#pragma mark * SimplePing// The SimplePing class is a very simple class that lets you send and receive Pings.@protocol SimplePingDelegate;@interface SimplePing : NSObject{ Nsstring * _hostname; NSData * _hostAddress; CFHostRef _host; CFSocketRef _socket; ID<SimplePingDelegate> _delegate; uint16_t _IDentifIEr; // host byte order uint16_t _nextSequenceNumber; // host byte order}+ (SimplePing *)simplePingWithHostname:(Nsstring *)hostname; // chooses first IPv4 address+ (SimplePing *)simplePingWithHostAddress:(NSData *)hostAddress; // contains (struct sockaddr)@property (nonatomic,assign,reaDWrite) ID<SimplePingDelegate> delegate;@property (nonatomic,copy,Readonly) Nsstring * hostname;@property (nonatomic,Readonly) NSData * hostAddress;@property (nonatomic,Readonly) uint16_t IDentifIEr;@property (nonatomic,Readonly) uint16_t nextSequenceNumber;- (voID)start; // Starts the Pinger object Pinging. You should call this after // you've setup the delegate and any Ping parameters.- (voID)sendPingWithData:(NSData *)data; // Sends an actual Ping. Pass nil for data to use a standard 56 byte payload (resulting in a // standard 64 byte Ping). Otherwise pass a non-nil value and it will be appended to the // ICMP header. // // Do not try to send a Ping before you receive the -simplePing:dIDStartWithAddress: delegate // callback.- (voID)stop; // Stops the Pinger object. You should call this when you're done // Pinging.+ (const struct ICMPheader *)icmpInPacket:(NSData *)packet; // Given a valID IP packet contains an ICMP,returns the address of the ICMP header that // follows the IP header. This doesn't do any significant valIDation of the packet.@end@protocol SimplePingDelegate <NSObject>@optional- (voID)simplePing:(SimplePing *)Pinger dIDStartWithAddress:(NSData *)address; // Called after the SimplePing has successfully started up. After this callback,you // can start sending Pings via -sendPingWithData:- (voID)simplePing:(SimplePing *)Pinger dIDFailWithError:(NSError *)error; // If this is called,the SimplePing object has Failed. By the time this callback is // called,the object has stopped (that is,you don't need to call -stop yourself).// important: On the send sIDe the packet does not include an IP header. // On the receive sIDe,it does. In that case,use +[SimplePing icmpInPacket:] // to find the ICMP header within the packet.- (voID)simplePing:(SimplePing *)Pinger dIDSendPacket:(NSData *)packet; // Called whenever the SimplePing object has successfully sent a Ping packet. - (voID)simplePing:(SimplePing *)Pinger dIDFailToSendPacket:(NSData *)packet error:(NSError *)error; // Called whenever the SimplePing object trIEs and fails to send a Ping packet.- (voID)simplePing:(SimplePing *)Pinger dIDReceivePingResponsePacket:(NSData *)packet; // Called whenever the SimplePing object receives an ICMP packet that looks like // a response to one of our Pings (that is,has a valID ICMP checksum,has // an IDentifIEr that matches our IDentifIEr,and has a sequence number in // the range of sequence numbers that we've sent out).- (voID)simplePing:(SimplePing *)Pinger dIDReceiveUnexpectedPacket:(NSData *)packet; // Called whenever the SimplePing object receives an ICMP packet that does not // look like a response to one of our Pings.@end#pragma mark * IP and ICMP On-The-Wire Format// The following declarations specify the structure of Ping packets on the wire.// IP header structure:struct IPheader { uint8_t versionAndheaderLength; uint8_t differentiatedServices; uint16_t totalLength; uint16_t IDentification; uint16_t flagsAndFragmentOffset; uint8_t timetolive; uint8_t protocol; uint16_t headerChecksum; uint8_t sourceAddress[4]; uint8_t destinationAddress[4]; // options... // data...};typedef struct IPheader IPheader;__Check_Compile_Time(sizeof(IPheader) == 20);__Check_Compile_Time(offsetof(IPheader,versionAndheaderLength) == 0);__Check_Compile_Time(offsetof(IPheader,differentiatedServices) == 1);__Check_Compile_Time(offsetof(IPheader,totalLength) == 2);__Check_Compile_Time(offsetof(IPheader,IDentification) == 4);__Check_Compile_Time(offsetof(IPheader,flagsAndFragmentOffset) == 6);__Check_Compile_Time(offsetof(IPheader,timetolive) == 8);__Check_Compile_Time(offsetof(IPheader,protocol) == 9);__Check_Compile_Time(offsetof(IPheader,headerChecksum) == 10);__Check_Compile_Time(offsetof(IPheader,sourceAddress) == 12);__Check_Compile_Time(offsetof(IPheader,destinationAddress) == 16);// ICMP type and code combinations:enum { kICMPTypeEchoReply = 0,// code is always 0 kICMPTypeEchoRequest = 8 // code is always 0};// ICMP header structure:struct ICMPheader { uint8_t type; uint8_t code; uint16_t checksum; uint16_t IDentifIEr; uint16_t sequenceNumber; // data...};typedef struct ICMPheader ICMPheader;__Check_Compile_Time(sizeof(ICMPheader) == 8);__Check_Compile_Time(offsetof(ICMPheader,type) == 0);__Check_Compile_Time(offsetof(ICMPheader,code) == 1);__Check_Compile_Time(offsetof(ICMPheader,checksum) == 2);__Check_Compile_Time(offsetof(ICMPheader,IDentifIEr) == 4);__Check_Compile_Time(offsetof(ICMPheader,sequenceNumber) == 6);总结
以上是内存溢出为你收集整理的在更新到Xcode9之后,我得到C需要所有声明的类型说明符全部内容,希望文章能够帮你解决在更新到Xcode9之后,我得到C需要所有声明的类型说明符所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)