FedoraForum.org - Fedora Support Forums and Community
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2009
    Posts
    38

    array type has incomplete element type

    #include<stdio.h>
    int main()
    {
    char sd[][]={"this","that" };


    }

    when I try to compile I am getting
    f.c: In function āmainā:
    f.c:4: error: array type has incomplete element type

    could somebody explain me the error

  2. #2
    Join Date
    Feb 2006
    Location
    Modbury, Australia
    Posts
    99

    Re: array type has incomplete element type

    You can not have multidimensional array without specifying the bounds.

    You probably want something like this:

    char *sd[] = { "this", "that" };

    maybe some example:


    #include <iostream>

    int main(int argc, char **argv)
    {
    char *sd[] = { "this", "that", 0 };

    for (int i = 0; sd[i]; ++i)
    {
    std::cout << sd[i] << "\n";
    }
    std::cout << std::endl;

    return 0;
    }

  3. #3
    Join Date
    Oct 2009
    Posts
    38

    Re: array type has incomplete element type

    Hi

    I have read in ANSI C by kernighan and Ritche that an object deaclared as an array type with out specifying the size of the array will be an incomplete type.
    section A.8.6.2

  4. #4
    Join Date
    Feb 2006
    Location
    Modbury, Australia
    Posts
    99

    Re: array type has incomplete element type

    that is correct. You need to specify the storage size. The compiler can not guess for you . . .

  5. #5
    Join Date
    Jul 2009
    Location
    England, UK
    Posts
    969

    Re: array type has incomplete element type

    Two-dimensional arrays in C are stored in a one-dimensional way internally, and (as ausadl says) the compiler doesn't try to guess at the size of the "inner" dimension.

    Things are more complicated because of course there is no proper string handling. I guess you really want an array of strings (not a two-dimensional array of chars), so it might be better to declare it as an array of pointers to char, then assign those pointers to memory allocated by malloc, or to string constants.

Similar Threads

  1. expecting a reference package element found type 0
    By Raskula in forum Hardware & Laptops
    Replies: 4
    Last Post: 4th January 2009, 02:31 PM
  2. error: dereferencing pointer to incomplete type
    By Maninder in forum Servers & Networking
    Replies: 0
    Last Post: 11th May 2008, 10:23 AM
  3. What to type
    By 357mag in forum Linux Chat
    Replies: 8
    Last Post: 21st January 2006, 10:46 PM
  4. error: array type has incomplete element type
    By jattoo in forum Using Fedora
    Replies: 4
    Last Post: 7th October 2005, 05:18 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •