PDA

View Full Version : Why why why why WHY WHY?



Red_Oddity
04-02-2006, 02:41 PM
WHY, am i not understanding the use of pointers and linked libraries...

Everytime i try doing plugins in C for LW i get held back by my utter and total lack of understanding of pointers (the way the LW plugins are build)
I understand LScript, i understand MEL, i understand some Java and some C...but the source code of plugins that have to be compiled as .p files are something my mind just doesn't seem willing to grasp...
Everytime i think i understand some inconsistancy pops up in some of the sample plugins in the LW SDK. Is it because the SDK is a somewhat of a work in progress? or never really updated? or did the programmers (Hastings and Fergus i believe) never really cleaned up their code enough for idoiots like me to understand?

Am i really this stupid, or is this something 'new programmers' are always strugling with?

Also, every stupid friggin' book on C seems to be more than happy to skip pointers, they all just scratch the surface of what is possible and seem to end with the most basic friggin programs (god, do these authors just LOOOOVE their stupid printf programs....)
Book stores are filled with books on C and C++, but none of the ones i found are explaining pointer and linking...

Does anyone know any good books that DO explain this? and in plain english if anywhere possible, with some examples NOT focused at the average database programmer?

RedBull
04-02-2006, 03:20 PM
The documentation was done by Ernie and Now Jarno/Anttii i beleive...
And Allen and Stuart had nothing to do with it...

The documentation is a little lacking, but it's designed as a Server Development Kit, and not as an introduction to LW C Programming...
Ernie makes it clear, that it's not for the faint hearted, and it's generally not an easy thing to work with.... So you were warned...

Search Google for pointers on pointers or join a DevC forum and ask a few questions.... Pointers have 1000's of uses, so it will be hard to find exact info.

The code examples itself are quite clean, and 99% of compiles without a single problem.

My advice stick to Lscript unless you have an absolute need for C/SDK.
There is simply not enough things you can do in the C/SDK that can't be done much more easily in Lscript these days.....

Unless you have a prowess in C, i prefer Lscript, it's just faster to write.
Many C forums and books do exist though....

prospector
04-02-2006, 03:24 PM
Did you see these?
http://www.cplusplus.com/doc/tutorial/pointers.html
http://www.codersource.net/c++_pointers.html
http://augustcouncil.com/~tgibson/tutorial/ptr.html
http://richardbowles.tripod.com/cpp/cpp18.htm

many more when googling C++ Pointers

all heiroglyphics to me

Tho I did download a compiler so I couls see if this is learnable

Red Bull...ya beat me

Sekhar
04-02-2006, 04:07 PM
Kernighan and Ritchie's "The C Programming Language" (http://cm.bell-labs.com/cm/cs/cbook/) is a classic. These guys created C.

GregMalick
04-02-2006, 07:36 PM
Hey Red,

If you want to PM me - maybe some short email conversations might clear things up a little.

p.s. I wish there was an online chat channel where LW plugin developers could congregate & chat. Forums & email are so slow that I understand you're wanting documentation that will help out. I'm assuming you've already found the plugin developers maliing list and have searched the archives for issues (of which there are many unresolved ones).

dballesg
04-03-2006, 02:10 AM
Hey Red,

If you want to PM me - maybe some short email conversations might clear things up a little.

p.s. I wish there was an online chat channel where LW plugin developers could congregate & chat. Forums & email are so slow that I understand you're wanting documentation that will help out. I'm assuming you've already found the plugin developers maliing list and have searched the archives for issues (of which there are many unresolved ones).

I vote for the chat channel as well, but with the time diference it can be a problem for europeans to talk with americans, unles one part stay without sleep! :) And that is something I can do less and less! :)

I understand as well Red_Oddity frustratons, happened to me as well.

I remeber I asked Chuck if there would be new SDK docs, he said he would ask and come back with an answer, but I didn't hear anything from him yet.

In the meantime I add this links as well:

Learn C/C++ Today: http://www.cyberdiem.com/vin/index.html
Cprogramming.com: http://www.cprogramming.com/

I have a ton more! :) So I will add few more when I go back home tonight! :)

Best regards,
David

Red_Oddity
04-03-2006, 02:47 AM
Wow, that's alot of replies in such a short time...thank you all guys.
I did try googling for pointers, and i have been reading a lot of those pages, but for some reason the way it is used in LW i still can't seem to grasp...
As for compiling, offcourse they all compile, that wasn't really the problem (thanx to Lynx3D's excellent tutorial)

I could offcourse just copy paste my plugin together, but i want to understand what i'm really doing.

GragMalick, i will certainly PM you with questions, i will however read some of the posted documentation first and try again to understand the wonderfull world of pointers in LW.

Well, back to staring a source codes again

colkai
04-03-2006, 02:58 AM
WHY, am i not understanding the use of pointers and linked libraries...
....
Am i really this stupid, or is this something 'new programmers' are always strugling with?

Hehe, trust me, I wrestled more than enough with pointers and such when I started learning C/C++.

When you get to an array of pointers to function pointers, your brain starts to melt. :p ;)

I used to have a cracking book, but it has long since been given to a friend who was studying at college.
Whilst not LW related, I do still have all my old C code and a fiar few test programs using pointers. If you like, I can put up a RAR file of the code here for you to take apart. Nothing useful, but it will show how the pointers work.

Red_Oddity
04-03-2006, 04:42 AM
Hehe, trust me, I wrestled more than enough with pointers and such when I started learning C/C++.

When you get to an array of pointers to function pointers, your brain starts to melt. :p ;)

I used to have a cracking book, but it has long since been given to a friend who was studying at college.
Whilst not LW related, I do still have all my old C code and a fiar few test programs using pointers. If you like, I can put up a RAR file of the code here for you to take apart. Nothing useful, but it will show how the pointers work.

That would be awsome, anything that would give me a little more insight into how this excactly works is a god send gift :)

ColinCohen
04-03-2006, 05:38 AM
Don't be too upset -- I have a university degree in computer science, and it took me some time after school (where they didn't teach C) to truly learn and understand the language.

But once I did, I came to appreciate it as the best language there is. And I still believe this.

I second the recommendation of the K&R book. It may be the best book ever written about a computer language. And it covers pointers in complete detail.

colkai
04-03-2006, 06:02 AM
That would be awsome, anything that would give me a little more insight into how this excactly works is a god send gift :)
Okey Dokey, I'm just about to head out for lunch, when I'm back, I'll slap all my old C code into an archive for you to peruse. Don't think there's anything in there I'm concerned about making publicly available. (Except for the embarassment of the crappy coding I did that is ;) ).

colkai
04-03-2006, 06:45 AM
Ok, here you go, you may have to wade through some of the code to find pointer examples, I wasn't exactly organised when I was learning. :p

Some of the code is taken from books, from magazines, etc. some I constructed as tests, some as small utilities back in the old MSDos 3.0 days.

When I get home tonight, I'll see if I still have any tut docs and info still around on my old CD's. I did keep quite a few notes back in the day but don't know if I've since "tidied up". ;)

Red_Oddity
04-03-2006, 08:22 AM
Thank you Colkai, i'm sure it will teach me some more instights into programming C.

Red_Oddity
04-03-2006, 08:35 AM
A quick question.

I'm trying to use LWBUF_MOTION_X and LWBUF_MOTION_Y the safe way, so i'm setting the Flags for the LWFilterAccess, BUT, the only example i could find on how to pass a single flag is in zcomp example.


return 1 << LWBUF_DEPTH;


As far as i understand this means it shifts the bits in the number 1 a certain amount, probably dictated by the value LWBUF_DEPTH represents, right?
How on earth do i string multiple buffer flags on this value?
So, how do i return LWBUF_MOTION_X and LWBUF_MOTION_Y at the same time.

Red_Oddity
04-03-2006, 08:49 AM
Hmmm...is this the right way to string these together and return them?


return 1 << LWBUF_MOTION_X | LWBUF_MOTION_Y;

GregMalick
04-03-2006, 09:19 AM
No sure about that example , I'd have to check the docs.
But I assume that the "bit position" is what is determining the Buffer Depth which is why the shift is being done.

Here are how flags are done in cyclone.c and it makes sense.



XCALL_(static unsigned int) CycloneFlags (Cyclone *inst) {
return (LWTEXF_HV_SRF | LWTEXF_HV_VOL | LWTEXF_DISPLACE | LWTEXF_AXIS);
}

Lightwolf
04-03-2006, 12:09 PM
Hmmm...is this the right way to string these together and return them?


return 1 << LWBUF_MOTION_X | LWBUF_MOTION_Y;

Nope, it would be:


return (1 << LWBUF_MOTION_X) | (1 << LWBUF_MOTION_Y);


Cheers,
Mike

Red_Oddity
04-03-2006, 12:32 PM
Brilliant, that works, thanx Lightwolf

Lightwolf
04-03-2006, 04:05 PM
Brilliant, that works, thanx Lightwolf
*grin* You're welcome!

Oh, and don't worry about pointers... you'll get them eventually. (Well, I did ... I think ;) ).

Cheers,
Mike

colkai
04-04-2006, 02:21 AM
Sorry to say I have absolutely no idea what I did with the tutorial text, I have the code, but not tha accompanying texts.
I can't beleive I've got rid of them completely so I'll keep search for you. :)