So I have a MacBook Pro 2017 and whenever I compile a program that as "void main", the compiler gives me a warning saying that the return type of main is not int...  void main(){  (...)  }
2571
What is the correct (most efficient) way to define the main() function in C and C++ — int main() or void main() — and why? And how about the arguments? If int main() then return 1 or return 0?  There are numerous duplicates of this question, including:       — For C++, with a very good answer indeed.     Related:
99037
I see this from time to time and want to know what it is. I did try google, but its filtering out the characters from the search. I have a few books that don't reference it either.   FWIW, I remember in pascal that is was the assignment operator.   Can anybody point me to the MSDN or similar page?
32521
I came across this strange code snippet which compiles fine:  class Car {     public:     int speed; };  int main() {     int Car::*pSpeed = &amp;Car::speed;     return 0; }   Why does C++ have this pointer to a non-static data member of a class? What is the use of this strange pointer in real code?
10581
I have the following code:  typedef void VOID; int f(void); int g(VOID);   which compiles just fine in C (using gcc 4.3.2 on Fedora 10). The same code compiled as C++ gives me the following error:  void.c:3: error: ‘&lt;anonymous&gt;’ has incomplete type void.c:3: error: invalid use of ‘VOID’   Now, this is something in external library and I would like the owner to fix that problem. So I have a question - does C++ standard forbids this construct? Could you give me a pointer/citation? The only thing I can recall is that function declaration with (void) to signal empty parameter list is deprecated in C++, but I don't understand why typedefed VOID does not work.
59976
I can't understand what these are even though I've read articles about them.  Does it have something to do with 32 bits and 64 bits CPU? So why is it saying "AMD"64 and "i386"?  AMD is a label just like Intel? So, if I've got an Intel Core 2 Duo (MacBook Pro), then I can't use AMD64 even though Intel Core is 64 bits.
81821
In the  library, they are overloading the () operator.  Is this a convention in C++? For callbacks, etc.?  I have seen this in code of a co-worker (who happens to be a big Boost fan). Of all the Boost goodness out there, this has only led to confusion for me.  Any insight as to the reason for this overload?
36363
Session transcript: &gt; type lookma.c int main() {   printf(&quot;%s&quot;, &quot;no stdio.h&quot;); }  &gt; cl lookma.c Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86 Copyright (C) Microsoft Corporation.  All rights reserved.  lookma.c Microsoft (R) Incremental Linker Version 8.00.50727.762 Copyright (C) Microsoft Corporation.  All rights reserved.  /out:lookma.exe lookma.obj  &gt; lookma no stdio.h
122778
I'm assuming that the good old qsort function in stdlib is not stable, because the man page doesn't say anything about it.  This is the function I'm talking about:     #include &lt;stdlib.h&gt;    void qsort(void *base, size_t nmemb, size_t size,               int(*compar)(const void *, const void *));     I assume that if I change my comparison function to also include the address of that which I'm comparing, it will be stable.  Is that correct?    Eg:  int compareFoos( const void* pA, const void *pB ) {     Foo *pFooA = (Foo*) pA;     Foo *pFooB = (Foo*) pB;      if( pFooA-&gt;id &lt; pFooB-&gt;id ) {         return -1;     } else if( pFooA-&gt;id &gt; pFooB-&gt;id ) {         return 1;     } else if( pA &lt; pB ) {         return -1;                 } else if( pB &gt; pA ) {        return 1;     } else {        return 0;     } }
118197
In C++, is the return type considered part of the function signature? and no overloading is allowed with just return type modified.
9770
I'm sure you all know the behaviour I mean - code such as:  Thread thread = new Thread(); int activeCount = thread.activeCount();   provokes a compiler warning.  Why isn't it an error?  EDIT:  To be clear: question has nothing to do with Threads.  I realise Thread examples are often given when discussing this because of the potential to really mess things up with them.  But really the problem is that such usage is always nonsense and you can't (competently) write such a call and mean it.  Any example of this type of method call would be barmy.  Here's another:  String hello = "hello"; String number123AsString = hello.valueOf(123);   Which makes it look as if each String instance comes with a "String valueOf(int i)" method.
89683
I wrote this program:  #include&lt;stdio.h&gt; int main() { printf(“Hello World\n”); return 0; }   I saved it as first.c and tried to compile but receiving this problem I have installed even gcc compiler too.  $ gcc first.c -o first1 first.c: In function ‘main’: first.c:4:1: error: stray ‘\342’ in program first.c:4:1: error: stray ‘\200’ in program first.c:4:1: error: stray ‘\234’ in program first.c:4:11: error: ‘Hello’ undeclared (first use in this function) first.c:4:11: note: each undeclared identifier is reported only once for each function  it appears in first.c:4:17: error: expected ‘)’ before ‘World’ first.c:4:17: error: stray ‘\’ in program first.c:4:17: error: stray ‘\342’ in program first.c:4:17: error: stray ‘\200’ in program first.c:4:17: error: stray ‘\235’ in program   How can I fix this problem?
24951
I wrote a function in C that converts a string to an integer and returns the integer. When I call the function I also want it to let me know if the string is not a valid number. In the past I returned -1 when this error occurred, because I didn't need to convert strings to negative numbers. But now I want it to convert strings to negative numbers, so what is the best way to report the error?  In case I wasn't clear about this: I don't want this function to report the error to the user, I want it to report the error to the code that called the function. ("Report" might be the wrong word to use...)  Here's the code:  s32 intval(const char *string) {     bool negative = false;     u32 current_char = 0;      if (string[0] == '-') {         negative = true;         current_char = 1;     }      s32 num = 0;     while (string[current_char]) {         if (string[current_char] &lt; '0' || string[current_char] &gt; '9') {             // Return an error here.. but how?         }          num *= 10;         num += string[current_char] - '0';         current_char++;     }      if (negative) {         num = -num;     }      return num; }
113560
I expected A::~A() to be called in this program, but it isn't:  #include &lt;iostream&gt;  struct A {   ~A() { std::cout &lt;&lt; "~A()" &lt;&lt; std::endl; } };  void f() {   A a;   throw "spam"; }  int main() { f(); }   However, if I change last line to   int main() try { f(); } catch (...) { throw; }   then A::~A() is called.  I am compiling with "Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86" from Visual Studio 2005. Command line is cl /EHa my.cpp.  Is compiler right as usual? What does standard say on this matter?
77250
My MS Visual C# program was compiling and running just fine. I close MS Visual C# to go off and do other things in life.  I reopen it and (before doing anything else) go to "Publish" my program and get the following error message:     Program C:\myprogram.exe does not contain a static 'Main' method suitable for an entry point   Huh?  Yes it does... and it was all working 15 min earlier.  Sure, I can believe that I accidentally hit something or done something before I closed it up... but what?  How do I troubleshoot this?    My Program.cs file looks like this:  using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using System.Threading;  namespace SimpleAIMLEditor {     static class Program     {         [STAThread]         static void Main()         {             Application.EnableVisualStyles();             Application.SetCompatibleTextRenderingDefault(false);              Application.Run(new mainSAEForm());         }     } }   ...and there are some comments in there.    There are no other errors.  Help?
11352
Duplicate:     Maybe this is a very silly question but I don't understand why I can't declare two methods that have the same signature when they have different return types.  public class MyClass {     private double d = 0;      public double MyMethod()     {         return d;     }      public string MyMethod()     {         return d.ToString();     } }   I get a compile error that states that the class already defines a member with the same parameter types.  (Obviously the way I'm using this in my code isn't as simple as my example code...but I think it gets the idea across.)  Am I missing something concerning OO design that makes what I'm trying to do an OOP anti-pattern? Surely the compiler should be able to determine which method I'm trying to use as long as I specifically tell it which one I want.  Given MyClass myClass = new MyClass(); I would expect the following code to work:  double d = myClass.MyMethod(); string s = myClass.MyMethod();   I would expect the following code to have problems:  var v = myClass.MyMethod();   But even in the case of var it should result in a compile error.  Can anyone see what I'm doing wrong here? I'm more than happy to be corrected. :-)
57093
I think there's a lot for me to learn about data types. Why this happens  double result = ((3/8)*100).ToString();   it gives zero .. should be 37,5 ... :(
122083
A colleague of mine recently got bitten badly by writing out of bounds to a static array on the stack (he added an element to it without increasing the array size).  Shouldn't the compiler catch this kind of error?  The following code compiles cleanly with gcc, even with the -Wall -Wextra options, and yet it is clearly erroneous:  int main(void) {   int a[10];   a[13] = 3;  // oops, overwrote the return address   return 0; }   I'm positive that this is undefined behavior, although I can't find an excerpt from the C99 standard saying so at the moment.  But in the simplest case, where the size of an array is known as compile time and the indices are known at compile time, shouldn't the compiler emit a warning at the very least?