Fedora Linux Support Community & Resources Center
  #1  
Old 6th October 2010, 11:16 AM
pushparaj_bits Offline
Registered User
 
Join Date: Oct 2009
Posts: 38
windows_xp_2003firefox
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
Reply With Quote
  #2  
Old 6th October 2010, 02:45 PM
ausadl Offline
Registered User
 
Join Date: Feb 2006
Location: Modbury, Australia
Posts: 99
linuxfirefox
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;
}
Reply With Quote
  #3  
Old 7th October 2010, 07:34 AM
pushparaj_bits Offline
Registered User
 
Join Date: Oct 2009
Posts: 38
windows_xp_2003firefox
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
Reply With Quote
  #4  
Old 7th October 2010, 08:37 AM
ausadl Offline
Registered User
 
Join Date: Feb 2006
Location: Modbury, Australia
Posts: 99
symbianunknown
Re: array type has incomplete element type

that is correct. You need to specify the storage size. The compiler can not guess for you . . .
Reply With Quote
  #5  
Old 7th October 2010, 12:35 PM
marriedto51 Online
Registered User
 
Join Date: Jul 2009
Location: England, UK
Posts: 821
linuxfedorafirefox
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.
Reply With Quote
Reply

Tags
array, element, incomplete, type

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
expecting a reference package element found type 0 Raskula Hardware & Laptops 4 4th January 2009 01:31 PM
error: dereferencing pointer to incomplete type Maninder Servers & Networking 0 11th May 2008 10:23 AM
What to type 357mag Linux Chat 8 21st January 2006 09:46 PM
error: array type has incomplete element type jattoo Using Fedora 4 7th October 2005 05:18 AM


Current GMT-time: 17:14 (Thursday, 23-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat