Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


iostream
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25796
Location: The netherlands

PostPosted: Thu Oct 13, 2011 10:23 am    Post subject: Reply with quote

One example is this. It compiles fine in gcc, but visual studio has a problem with it last time I tried (vs2008)

Code:

#include <stdio.h>

int dohorriblething(int x)
{
  char wtf[x];
  printf("weeee2\n");
  char wtf2[x*2];

 
  wtf[x-1]=x*x;
  wtf2[x*2-1]=wtf[x-1]+x;
 
  return wtf[x-1]+wtf2[x*2-1];
 
}

void main(void)
{
  printf("weeee\n");
  int randomvarhere=8;
  printf("randomvarhere=%d\n", randomvarhere);
  int f=dohorriblething(randomvarhere);


  printf("f=%d\n", f);
}

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Thu Oct 13, 2011 11:18 am    Post subject: Reply with quote

First glance I can say that:

Code:

int dohorriblething(int x)
{
  char wtf[x];
  ...


Wont compile because the array isn't constant. Which is against the C++ standards.

5.19 Constant Expressions:
In several places, C++ requires expressions that evaluate to an integral or enumeration constant. (See section 8.3.4 for array specific info.)

After that fails everything that relies on it will fail as well. Everything else looks fine though aside from the 'dohorriblething' func.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Thu Oct 13, 2011 1:46 pm    Post subject: Reply with quote

actually that's a variable-length array which was a new feature in c99. one guess at why it doesn't work with vc++ is because when visual studio is made to work with c files (.c type), it uses its own c compiler which supports only c89/c90 with a few extensions. see this page for more info:

http://social.msdn.microsoft.com/Forums/en/vcprerelease/thread/6099f453-db2c-49c3-b59a-b799c379cebb

i don't have vc++ handy now but when i do i can look into it and confirm whether that is the reason
Back to top
View user's profile Send private message
AverageAzn247
Grandmaster Cheater
Reputation: 34

Joined: 01 Oct 2007
Posts: 909
Location: Austin,TX with 72 virgins

PostPosted: Thu Oct 13, 2011 1:49 pm    Post subject: Reply with quote

heres one. http://www.mediafire.com/?ce60xmmatamzvj9
_________________


Waxxup wrote:
What are Night Elves?
A girl group?
Back to top
View user's profile Send private message MSN Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Thu Oct 13, 2011 3:28 pm    Post subject: Reply with quote

Slugsnack wrote:
actually that's a variable-length array which was a new feature in c99. one guess at why it doesn't work with vc++ is because when visual studio is made to work with c files (.c type), it uses its own c compiler which supports only c89/c90 with a few extensions. see this page for more info:

http://social.msdn.microsoft.com/Forums/en/vcprerelease/thread/6099f453-db2c-49c3-b59a-b799c379cebb

i don't have vc++ handy now but when i do i can look into it and confirm whether that is the reason


Visual Studio doesn't support past c90 as you mentioned so a handful of C standard things aren't directly supported. There are some workarounds implemented to support some of the features loosely though; such as for variable-length arrays:
http://msdn.microsoft.com/en-us/library/zb1574zs.aspx

My above info referred directly to the C++ standards and not C's.

From the n3242.pdf copy of the standards for C++ variable length arrays are not mentioned / validated in the PDF that I can find. Only mentioning points on initialization are things such as:

5.19 - 3
Quote:
A constant expression is an integral constant expression if it is of integral or enumeration type. [ Note: Such
expressions may be used as array bounds (8.3.4, 5.3.4), as case expressions (6.4.2), as bit-field lengths (9.6),
as enumerator initializers (7.2), and as integral or enumeration non-type template arguments (14.3).—end
note ]


8.3.4 - Section specific to arrays in general. (looks cleaner in the docs cause of the subscriptions and such used to format..)
Quote:

In a declaration T D where D has the form
D1 [ constant-expressionopt] attribute-specifier-seqopt


And so on.

Some other links:
http://stackoverflow.com/questions/1887097/variable-length-arrays-in-c
http://groups.google.com/group/comp.std.c++/browse_thread/thread/2bfe25800d4961e8/9545494bbb336dfa?pli=1

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Thu Oct 13, 2011 3:41 pm    Post subject: Reply with quote

AverageAzn247 wrote:
heres one. http://www.mediafire.com/?ce60xmmatamzvj9


With Visual Studio 2010 I get:

Code:

menu.cpp(74): warning C4390: ';' : empty controlled statement found; is this the intent?
menu.cpp(47): warning C4101: 'records' : unreferenced local variable

prw.cpp(23): warning C4715: 'operator>>' : not all control paths return a value
prw.cpp(53): error C4716: 'operator>>' : must return a value
prw.cpp(63): warning C4715: 'operator>>' : not all control paths return a value
prw.cpp(108): error C4716: 'operator>>' : must return a value
prw.cpp(201): warning C4715: 'get_string_input' : not all control paths return a value



Which is legitimate given that the errors here are valid.

In menu.cpp there is:
Code:
      if (!(infile>>num));


This does nothing. The other warning is due to a local variable being unused so thats not a big deal.

In prw.cpp there are multiple cases where you overload an operator and don't give a return value where one is expected. Such as:

Code:

ifstream& operator>>(ifstream& is, Category& m)   // PRW: overloads >> for Category type in an ifstream
{
   int cat_id;         // PRW: variables to store read data
   string cat_name;
   is >> cat_id >> cat_name;
   if (!is) return is;
   m = Category(cat_id, cat_name);
}


Has no end-return after m = Category( .. ); Same with the get_string_input function, it is missing a return path.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Thu Oct 13, 2011 4:37 pm    Post subject: Reply with quote

presumably dark byte is refering to a C source since it imports stdio.h which is part of the c runtime, not the c++ runtime. i agree it should not even compile, not because it is against c++ standards, but against c89/c90. it should not be being compiled against c++ standards at all.

yes confirmed, as i thought compiling in vc++ will give error C2057: expected constant expression on 'char wtf[x];'. also void main ?! compiling for c++ will get the same error.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites