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 


any C programmer here?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Random spam
View previous topic :: View next topic  
Author Message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Wed Jun 06, 2012 8:42 pm    Post subject: any C programmer here? Reply with quote

I need some help D:
Back to top
View user's profile Send private message MSN Messenger
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Wed Jun 06, 2012 8:51 pm    Post subject: Reply with quote

me pick me
Back to top
View user's profile Send private message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Wed Jun 06, 2012 9:02 pm    Post subject: Reply with quote

so, I'm doing this
Code:

typedef struct {
   int x;
   int y;
   int z;
} Vector3;

typedef struct {
   int x;
   int y;
}Vector2;

typedef struct{
   Vector3 parent;
   Vector3 child;
}Bone;

typedef struct {
   Vector3 *positions;
   Vector3 *normals;
   Vector2 *uvs;
   Bone *bones;
}cModel;


using pointers on positions normals uvs and bones because I found that using that method I could use

Code:

cModel model1;
int size;

model.positions = malloc(size* sizeof *model.positions ); 


to make it a flexible array ?

and then use
model.positions[45912]

is it correct?
Back to top
View user's profile Send private message MSN Messenger
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Wed Jun 06, 2012 9:09 pm    Post subject: Reply with quote

yes you can do this. it's more common/idiomatic in C to use an array of size 1 actually:
http://blogs.msdn.com/b/oldnewthing/archive/2004/08/26/220873.aspx

size 0 arrays are also common:
http://stackoverflow.com/questions/295027/array-of-zero-length

however, note that 0 length array is not part of the standard (at least not c89 or c99). they are however a gnu extension. so for example, compile with -std=gnu99. if you are using c99 and your struct is going to be scoped to a function or less, you can avoid the malloc all together by using VLAs. for example:

Code:
#include <stdlib.h>
#include <stdio.h>

struct lala_s {
   int * lala;
};

void func1(int x)
{
   struct lala_s s;
   int         arr[x];
   
   s.lala = arr;

   for(int i = 0; i < x; i++) {
      s.lala[i] = i;
   }

   for(int i = 0; i < x; i++) {
      printf("%d\n", s.lala[i]);
   }
}

int main(void)
{
   func1(10);
   return EXIT_SUCCESS;
}


compile with:

Code:
gcc -std=c99 -Wall -pedantic lala.c -o lala


Last edited by Slugsnack on Wed Jun 06, 2012 9:54 pm; edited 3 times in total
Back to top
View user's profile Send private message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Wed Jun 06, 2012 9:20 pm    Post subject: Reply with quote

I'm not really sure of what C I'm using, it is the one used by Blackberry native sdk

I tried
Vector3 position[0];

and it built with no errors,

thanks :3
Back to top
View user's profile Send private message MSN Messenger
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Wed Jun 06, 2012 9:32 pm    Post subject: This post has 1 review(s) Reply with quote

just because it compiles without errors does not mean that it guarantees it will work. for example, gcc is not strictly conformant with the c99 standard. hence if you try to compile a source with a 0 size array it will give a warning instead of an error. you would only spot the warning if you compiled with -pedantic.

the problem in this case is that if you are not sure whether your compiler is standard conformant, you could well be relying on undefined behaviour. and by definition that is... undefined. it could do anything. restart your phone. display random porno pictures when your mother picks up the phone, etc.

at the very least check that your compiler is supporting 0 size array through some extension (this is what gnu does)
Back to top
View user's profile Send private message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Wed Jun 06, 2012 9:41 pm    Post subject: Reply with quote

Shrooms -> on a contest on blackberry playbook apps
I'm making 3D games

slugnack-> using pointers ten would be a better option ?
like what is the difference between using an array 0 or a pointer?
I believe difference between using an array 0 and an array 1 is just a little of optimization not storing a data space but with a pointer I'm not sure.

I still don't really understand pointers fully.
Back to top
View user's profile Send private message MSN Messenger
Channel GannoK
pffrt
Reputation: 130

Joined: 12 Apr 2008
Posts: 608

PostPosted: Wed Jun 06, 2012 9:44 pm    Post subject: This post has 1 review(s) Reply with quote

Slugsnack being a bro

+1

_________________
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Wed Jun 06, 2012 9:45 pm    Post subject: Reply with quote

i just told you. the difference is that one is well-defined by the standard and the other is undefined behaviour (or at least is less portable if used via an extension). either you don't care about portability. in which case check for an extension or use array of size 1. otherwise just use a pointer...

there are minor optimisations but they shouldn't really concern you at this stage
Back to top
View user's profile Send private message
Barnold Swolezzenegger
Cheater
Reputation: 20

Joined: 12 Mar 2011
Posts: 45

PostPosted: Wed Jun 06, 2012 9:51 pm    Post subject: Reply with quote

GannoK wrote:
Slugsnack being a bro

+1

You act like he's always a massive faggot. When you guys aren't being immature about everything, he's usually not bad.. You guys just always go into faggot tryhard mode and argue with him.
Back to top
View user's profile Send private message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Wed Jun 06, 2012 9:51 pm    Post subject: Reply with quote

ok ok

thanks :3
Back to top
View user's profile Send private message MSN Messenger
Channel GannoK
pffrt
Reputation: 130

Joined: 12 Apr 2008
Posts: 608

PostPosted: Wed Jun 06, 2012 9:56 pm    Post subject: Reply with quote

Apotheoun wrote:
GannoK wrote:
Slugsnack being a bro

+1

You act like he's always a massive faggot. When you guys aren't being immature about everything, he's usually not bad.. You guys just always go into faggot tryhard mode and argue with him.


I have never had a problem with slugsnack.......

_________________
Back to top
View user's profile Send private message
Barnold Swolezzenegger
Cheater
Reputation: 20

Joined: 12 Mar 2011
Posts: 45

PostPosted: Wed Jun 06, 2012 9:57 pm    Post subject: Reply with quote

I was generalizing the forum.
Back to top
View user's profile Send private message
Aniblaze
Grandmaster Cheater Supreme
Reputation: 138

Joined: 23 Apr 2006
Posts: 1757
Location: The Netherlands

PostPosted: Thu Jun 07, 2012 7:25 am    Post subject: Reply with quote

Apotheoun wrote:
I was generalizing the forum.

Based on a minority.
Back to top
View user's profile Send private message
Butters
Grandmaster Cheater Supreme
Reputation: 71

Joined: 17 Mar 2007
Posts: 1373

PostPosted: Thu Jun 07, 2012 8:15 am    Post subject: Reply with quote

Aniblaze wrote:
Apotheoun wrote:
I was generalizing the forum.

Based on a minority.
Which consists of about 5 people.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Random spam All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 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