NO

Author Topic: The auto keyword  (Read 4638 times)

Offline dezmand07

  • Member
  • *
  • Posts: 6
The auto keyword
« on: February 17, 2023, 08:08:40 AM »
Hello.
I switched from Visual Studio to Pelles C.
Why is the auto keyword implemented in Pelles C if it doesn't work?
Code: [Select]
auto hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
Quote
warning #2099: Missing type specifier; assuming 'int'.
error #2082: Invalid initialization type; expected 'int' but found 'void *'.
error #2168: Operands of '=' have incompatible types 'int' and 'void *'.
« Last Edit: February 17, 2023, 08:11:01 AM by dezmand07 »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: The auto keyword
« Reply #1 on: February 17, 2023, 11:20:00 AM »
Code: [Select]
HANDLE CreateToolhelp32Snapshot(  [in] DWORD dwFlags,  [in] DWORD th32ProcessID);CreateToolhelp32Snapshot returns a HANDLE, not int.
May the source be with you

Offline John Z

  • Member
  • *
  • Posts: 860
Re: The auto keyword
« Reply #2 on: February 17, 2023, 11:20:52 AM »
Hi dezmand07,

I think perhaps a misunderstanding of the use. 
The 'auto' keyword does not determine the type it determines the scope, location, initial value and where stored.

So the use of auto in the case below is missing the return value type HANDLE.

Attached is a helpful table on storage classes sourced from from https://www.geeksforgeeks.org/storage-classes-in-c/

John Z

Offline dezmand07

  • Member
  • *
  • Posts: 6
Re: The auto keyword
« Reply #3 on: February 17, 2023, 12:42:55 PM »
Code: [Select]
HANDLE CreateToolhelp32Snapshot(  [in] DWORD dwFlags,  [in] DWORD th32ProcessID);CreateToolhelp32Snapshot returns a HANDLE, not int.
Yes I know that. That is why I did not in vain mention about Visual Studio.
I thought that in Pelles C it's implemented.

Offline dezmand07

  • Member
  • *
  • Posts: 6
Re: The auto keyword
« Reply #4 on: February 17, 2023, 12:45:02 PM »
Attached is a helpful table on storage classes sourced from from https://www.geeksforgeeks.org/storage-classes-in-c/
Thank you. This clears things up a bit.

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: The auto keyword
« Reply #5 on: February 17, 2023, 09:24:39 PM »
MS C is MS C, not a C standard compliant at all.
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide