I am getting warnings when declaring and using the static variables.
static int m_chSequenceChar;
@interface data : NSObject
{
}
-(id)init;
-(void)initialze;
@end
@implementation data
- (id)init
{
m_chSequenceChar= 0;
}
+ (void)initialize
{
m_chSequenceChar= 0;
}
@end
Warning: 'm_chSequenceChar' defined but not used
EDITED:
data.h
------
static int m_nMessageId; //Message ID
static int m_uSessionId; //Session ID
static int m_chSequenceChar; //Sequence ID
static int* m_pData; //Integer buffer to carry dat开发者_JAVA技巧a
static int m_uDataSize; //Datasize
@interface data : NSObject {
@public
}
data.m
------
@implementation data
+ (void)initialize
{
m_uSessionId = 0;
m_chSequenceChar= 0;
m_nMessageId = 0;
m_pData = 0;
m_uDataSize = 0;
}
- (id) initWithID:(int) uMessageId withData:(id)pData withSize:(size_t) uDataSize
{
if(self=[super init])
{
// Initialize the member variables
m_uSessionId = 0xFF;
m_chSequenceChar= 10;
// Initialize values from derived class
m_nMessageId = uMessageId;
m_pData = (int*)pData;
m_uDataSize = (int)uDataSize;
}
NSLog(@"Data size:%d",uDataSize);
NSLog(@"m_pData:%d",m_pData);
NSLog(@"pData:%d",pData);
data* dat = [data alloc];
return self;
}
@end
That’s because you’re not reading the value of m_chSequenceChar
in your code. If you’re not reading it, you’re not using it, hence the warning.
Also, are you sure you want to reset m_chSequenceChar
to 0
whenever an instance of data
receives -init
? In general, +initialize
should be enough. And, in fact, you don’t even need to explicitly set it to 0
.
精彩评论