0

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 data
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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

7 Comments

@Beata Have you changed your code to use that variable? If so, edit your question and paste the code.
@Beata Your new code does not read/use m_chSequenceChar either: you’re assigning it values but you are not reading/using the variable at all. And the fact that you’re assigning it a value inside -init makes me thing you do not want a class variable in the first place.
@Bavarious: I want it as the class variables.See in the edited code i'm not using -(init) method to intialise.I'm using +(void)initialize function.I'm using all the variables on another function inside the same class to print the values.When called that method
@Beata You do have an instance initialiser: -initWithID… and you are assigning a value to that variable — see m_chSequenceChar= 10;. In fact, you’re using the instance initialiser to assign values to class variables, the same variables you also assign in +initialize. And your pasted code does not show this ‘another function’ that is supposed to read the variable, which is what I had asked you in my first comment.
@Beata Also, by declaring those variables in the header file you end up declaring them in every implementation file that imports/includes that header file. Move the declaration of those variables to the (single) implementation file that actually uses them.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.