Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Does this code violate rule #8.7?
#1
Given this example
Code:
file1.c:
        static int i;
        int j[1] = { i };
file2.c:
        extern int j[1];
        void f()
            {
            int k = j[0];
            }
Does this code violate rule #8.7, "Objects shall be defined at block scope if they are only accessed from within a single function"?
Reply
#2
The code fragment in file1.c needs a little more context in order to answer the question.

Is the intention that the definition of j occur outside of any block?

The initialisation of j seems to violate constraints because initialisers for objects with static storage duration must be constant expressions.

Please could you amend the example?
Posted by and on behalf of the MISRA C Working Group
Reply
#3
Suppose the types of 'i' and 'k' in this example were pointers to functions; would such make any difference?
Reply
#4
There is still insufficient information to answer the question fully. I have sent a private message to gs asking for clarification. Please can you read and reply to this?
Posted by and on behalf of the MISRA C Working Group
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)