Web lists-archives.com

Re: [Mingw-users] MinGW syntax error near unexpected token '('




On 20/12/15 08:07, Kbam7 wrote:
> I have been learning C for the past month now and I have managed to set up a
> local environment to compile and execute basic programs as I go along with
> the C tutorial I am following. Everything was working fine until yesterday.
> Suddenly, for a reason unknown to me, the compiler started to give me the
> following error:
> 
> ./hello.c: line 3: syntax error near unexpected token '('
> ./hello.c: line 3: 'int main ()'

This doesn't look like an error reported by the compiler; it DOES look
EXACTLY like the error the bash shell would produce, if you were to
attempt to execute trivial C source as a shell script[*]:

  $ cat foo.c
  #include <stdio.h>
  int main (){ return 0; }

  $ chmod +x foo.c

  $ ./foo.c
  ./foo.c: line 2: syntax error near unexpected token `('
  ./foo.c: line 2: `int main (){ return 0; }'

[*] This is run in bash shell on Linux, hence the 'chmod +x foo.c' to
(bogusly) make the C source APPEAR to be executable.

> The file hello.c contains basic code to print "Hello World!" in the command
> prompt window. The code is pasted below for your reference:
> 
> < --------------------------------------
> 
> #include <stdio.h>
> 
> int main()
> {
> /* Print "Hello World" on screen */
> printf("Hello, World!\n");
> 
>  return 0; 
> }
> 
> -------------------------------------- >
> 
> As you can see there is nothing wrong with the code.

No, there doesn't appear to be.  However, my example is a reduced
equivalent, insofar as it exhibits identical incorrect behaviour when it
is used inappropriately, as I have suggested.  You need to paste the
EXACT sequence of commands you used, to confirm whether or not you have
misused your source in an equivalent manner, in bash shell in MSYS.

> So for some reason, something went wrong with MinGW i think.

I think not!  Why would you think this, (unless YOU have modified your
MinGW installation in some detrimental way)?  Software isn't subject to
mechanical wear-and-tear, which might degrade its behaviour over time;
given identical conditions of use, it will produce identically the same
results time after time.

> I have done a search on Google [finding this] on Stack Exchange
> <http://stackoverflow.com/questions/17585748/unexpected-syntax-error-from-mingw-compiling-a-simple-c-program>  
> but I did not find a solution there either.

Be VERY cautious, and indeed sceptical, with advice on Stack Exchange;
there may be the occasional pearl of wisdom, but they tend to be bogged
down in a quagmire of misconception, ill advised, and often just plain
incorrect...

> One person there suggested the use of Dev-C++ which I downloaded and
> installed but I have no clue what to do with it.

...and this is just typical of the inappropriateness of much of the
advice you will find there.  No doubt, Dev-C++ may be a good product,
but advising you to use it in no way actually addresses the issue at
hand, so it most definitely is NOT a "solution".

-- 
Regards,
Keith.

Public key available from keys.gnupg.net
Key fingerprint: C19E C018 1547 DE50 E1D4 8F53 C0AD 36C6 347E 5A3F

Attachment: signature.asc
Description: OpenPGP digital signature

------------------------------------------------------------------------------
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx

This list observes the Etiquette found at 
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:mingw-users-request@xxxxxxxxxxxxxxxxxxxxx?subject=unsubscribe