Hi everyone! I usually use both above mentioned compilers but I have noticed that this little code (below) in VS 2015 CE compiles and works, while in XCode it returns me an error:
#include <iostream>
#include "std_lib_facilities.h"
char* findx(constchar* s, constchar* x)
{
int count_s = 0;
while (s[count_s] != 0)
{
int count_x = 0;
while (x[count_x] != 0)
{
if (s[count_s] == x[count_x])
{
cout << "Found match " << x[count_x] << " at X[" << count_x
<< "] with " << s[count_s] << " at S[" << count_s
<< "]" << endl;
return 0;
break;
}
++count_x;
}
++count_s;
}
cout << "Match " << *x << " not found" << endl;
return 0;
}
int main()
{
char* p = newchar[6]{ "Zorro" };
char* p1 = newchar[4]{ "Zio" };
findx(p, p1);
delete[] p;
delete[] p1;
keep_window_open();
return 0;
}
The error I got in XCode are:
1 2
char* p = newchar[6]{ "Zorro" }; // Initializer-string for char array is too long
char* p1 = newchar[4]{ "Zio" }; // Initializer-string for char array is too long
Thank you!
P.S. What do you feel to advice? I prefer XCode but I am not an experienced programmer so I trust you!
Compile your programs with both compilers with warnings set to high levels and and strict conformance with the standard demanded. This way, you have a much better chance of writing correct (conforming) C++ code.
Mostly, both will behave alike. But sometimes one compiler would be right (as the Microsoft compiler is in this case) and the other wrong; there would be other situations where the LLVM compiler is right and the Microsoft compiler wrong.
Interesting (no error on line 3, but line 5 is a different story altogether):
1 2 3 4 5 6 7 8
int main()
{
char c[6]{ "Zorro" };
char* p = newchar[6]{ "Zorro" };
return p[0] - c[0] ;
}
msc++ 1800 (VS 2013): 'initializing' : cannot convert from 'initializer-list' to 'char [6]'
Element '1': no conversion from 'const char [6]' to 'char' http://rextester.com/NEEQ54566
AFAIK, msc++ 1900 (VS 2015) which compiles this cleanly is the conforming C++ implementation wrt this.
Ok thank you very much Cubbi! You were very exhaustive!
Another question.. I know that is personal and depends on many things and preferences but which IDE do you advice me? I am a newbie and I am using VS or XCode among the dozen there are out there! :)
My advice would be, while a beginner, use as many as you can get your hands on, so that you won't be surprised when life puts you in front of one you didn't expect. Personally, I use the text editor vi most of the time.