I also tried the same on Cygwin which has GCC and G++ compilers installed.It also did not throw any error to me for .c file and threw the following error for .cpp file:
$ g++ practice.cpp practice.cpp: In function `int main()': practice.cpp:4: error: initializer-string for array of chars is too long I ran this piece of code on GCC compiler: #include<stdio.h> int main() { char str[7]="strings"; int i=printf("%s\n",str); printf("%d %d %d\n",i,sizeof(str)/sizeof(str[0]),strlen(str)); return 0; } and it yielded: kt...@akjlab /cygdrive/f/Code/linux $ gcc practice.c kt...@akjlab /cygdrive/f/Code/linux $ kt...@akjlab /cygdrive/f/Code/linux $ kt...@akjlab /cygdrive/f/Code/linux $ ./a.exe strings 8 7 7 Regards, Ashish On Fri, Jun 25, 2010 at 9:06 PM, Ashish kumar Jain <akjlucky4...@gmail.com>wrote: > It is legal in ANSI C (and perhaps in a few pre-ANSI systems), though > useful only in rare circumstances. > > This is running without any error on Dev cpp which has GCC compiler.It is > illegal in C++ where strict type checking is already in place. > > If someone differs from me,please let me know how you ran this piece of > code.First thing should be that it is a pure .c file and not .cpp file. > > Had it been not the case and you ran it in C++ environment,then it will > surely throw error for array bounds overflow. > > Regards, > > Ashish > > > On Sun, Jun 13, 2010 at 3:03 PM, sankalp srivastava < > richi.sankalp1...@gmail.com> wrote: > >> don't ever use a TC compiler , the most obsolete and mad compiler of all . >> Every compiler tries to fix the bug in ur code by some way or the other >> using some .Even gcc has a lot of bugs , in the sense it will return an exit >> status even if returning a void , but this is on ubuntu and haven't tries >> mingW yet . Any >> >> >> On Sun, Jun 13, 2010 at 1:47 PM, divya jain <sweetdivya....@gmail.com>wrote: >> >>> i use tc >>> >>> >>> On 13 June 2010 13:11, ram <karthik.gin...@gmail.com> wrote: >>> >>>> @rohit bro >>>> >>>> http://www.mingw.org/ >>>> >>>> *MinGW*, a contraction of "Minimalist GNU for Windows", is a port of >>>> the GNU Compiler Collection (GCC), and GNU Binutils, for use in the >>>> development of native Microsoft Windows applications. >>>> >>>> >>>> >>>> >>>> >>>> *From:* algogeeks@googlegroups.com [mailto:algoge...@googlegroups.com] >>>> *On Behalf Of *Rohit Saraf >>>> *Sent:* 13 June 2010 08:19 >>>> >>>> *To:* algogeeks@googlegroups.com >>>> *Subject:* Re: [algogeeks] c array >>>> >>>> >>>> >>>> @ram : i guess you have used some longer string and not "strings" >>>> >>>> >>>> >>>> btw.. what is Mingw ? >>>> >>>> gcc/g++ is not mingw, i guess >>>> >>>> >>>> -------------------------------------------------- >>>> Rohit Saraf >>>> Second Year Undergraduate, >>>> Dept. of Computer Science and Engineering >>>> IIT Bombay >>>> http://www.cse.iitb.ac.in/~rohitfeb14<http://www.cse.iitb.ac.in/%7Erohitfeb14> >>>> >>>> On Sun, Jun 13, 2010 at 8:13 AM, ram <karthik.gin...@gmail.com> wrote: >>>> >>>> D:\code\samplecode\main.cpp|5|error: initializer-string for array of >>>> chars is too long| >>>> >>>> >>>> >>>> I get this error on gcc (Mingw) . >>>> >>>> >>>> >>>> Though the array indexing starts from 0. >>>> >>>> The length specified in char str[7] is always straightforward . in this >>>> case char str[7] . the length of str is seven not eight ;hence the error >>>> >>>> -- >>>> >>>> ram >>>> >>>> >>>> >>>> *From:* algogeeks@googlegroups.com [mailto:algoge...@googlegroups.com] >>>> *On Behalf Of *sharad kumar >>>> *Sent:* 13 June 2010 07:59 >>>> *To:* algogeeks@googlegroups.com >>>> *Subject:* Re: [algogeeks] c array >>>> >>>> >>>> >>>> hey array indexing starts from 0 rite?? >>>> then y shld u get overflow in first place...... >>>> s t r i n g s \0 >>>> 0 1 2 3 4 5 6 7 >>>> >>>> On Sat, Jun 12, 2010 at 9:14 PM, divya <sweetdivya....@gmail.com> >>>> wrote: >>>> >>>> #include<stdio.h> >>>> int main() >>>> { >>>> >>>> char str[7]="strings"; >>>> printf("%s\n",str); >>>> return 0; >>>> } >>>> >>>> here i m nt getting overflow error whereas if i write stringss instead >>>> of strings then there is overflow error.. isnt null stored after s in >>>> strings nd 1st case shd also give overflow??? >>>> >>>> -- >>>> >>>> You received this message because you are subscribed to the Google >>>> Groups "Algorithm Geeks" group. >>>> To post to this group, send email to algoge...@googlegroups.com. >>>> >>>> To unsubscribe from this group, send email to >>>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> >>>> . >>>> For more options, visit this group at >>>> http://groups.google.com/group/algogeeks?hl=en. >>>> >>>> >>>> >>>> >>>> -- >>>> yezhu malai vaasa venkataramana Govinda Govinda >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Algorithm Geeks" group. >>>> To post to this group, send email to algoge...@googlegroups.com. >>>> To unsubscribe from this group, send email to >>>> algogeeks+unsubscr...@googlegroups.com. >>>> For more options, visit this group at >>>> http://groups.google.com/group/algogeeks?hl=en. >>>> >>>> -- >>>> >>>> You received this message because you are subscribed to the Google >>>> Groups "Algorithm Geeks" group. >>>> To post to this group, send email to algoge...@googlegroups.com. >>>> To unsubscribe from this group, send email to >>>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> >>>> . >>>> For more options, visit this group at >>>> http://groups.google.com/group/algogeeks?hl=en. >>>> >>>> >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Algorithm Geeks" group. >>>> To post to this group, send email to algoge...@googlegroups.com. >>>> To unsubscribe from this group, send email to >>>> algogeeks+unsubscr...@googlegroups.com. >>>> For more options, visit this group at >>>> http://groups.google.com/group/algogeeks?hl=en. >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Algorithm Geeks" group. >>>> To post to this group, send email to algoge...@googlegroups.com. >>>> To unsubscribe from this group, send email to >>>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> >>>> . >>>> For more options, visit this group at >>>> http://groups.google.com/group/algogeeks?hl=en. >>>> >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Algorithm Geeks" group. >>> To post to this group, send email to algoge...@googlegroups.com. >>> To unsubscribe from this group, send email to >>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> >>> . >>> For more options, visit this group at >>> http://groups.google.com/group/algogeeks?hl=en. >>> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algoge...@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> >> . >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.