Thread: C99, constant pointer to array of unspecified bound issue

  1. #1
    Registered User
    Join Date
    Feb 2016
    Posts
    1

    C99, constant pointer to array of unspecified bound issue

    I have question that is specific to C99 standard. The following declaration compiles without problem:

    void func(int (*const arr)[]);

    However, this declaration triggers error message "missing array size" (using Pelles C compiler):

    void func(int arr[const][]); /* actually this declaration should be identical to previous one */

    Does standard say something about this specific case?

    Also, I wonder, whether "static const exp" is allowed in brackets without at least one type qualifier, e.g.:

    void func(int arr[const static 10]); /* this is allowed */

    void func(int arr[static 10]); /* what about this? */

    Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > void func(int arr[const][]); /* actually this declaration should be identical to previous one */
    Well it isn't, because you have const inside the square brackets.

    > void func(int (*const arr)[]);
    Which if you substitute array notation leads back to
    void func(int const arr[][]);

    Since you must specify the size of all minor dimensions, you end up with the pelles compiler warning of "missing array size"

    So try
    void func(int (*const arr)[10]);
    void func(int const arr[][10]);



    > void func(int arr[const static 10]); /* this is allowed */
    > void func(int arr[static 10]); /* what about this? */
    A literal constant of 10 is both those things to begin with, so nothing is gained, even if it were valid.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is a array name is a constant pointer?
    By Bob Kang in forum C Programming
    Replies: 17
    Last Post: 07-02-2015, 11:06 PM
  2. Issue with multicast when socket isn't bound to INADDR_ANY
    By Clairvoyant1332 in forum Networking/Device Communication
    Replies: 1
    Last Post: 12-07-2011, 09:11 PM
  3. write an array of unspecified size to a file
    By c++guy in forum C++ Programming
    Replies: 3
    Last Post: 09-22-2010, 10:54 PM
  4. reading from file of unspecified size into array
    By AJOHNZ in forum C++ Programming
    Replies: 15
    Last Post: 08-22-2009, 01:21 PM
  5. array out of bound seg fault
    By ephemeralz in forum C Programming
    Replies: 1
    Last Post: 12-02-2003, 07:15 PM

Tags for this Thread