Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
Couple bugs
Dec 12, 2017, 5:42 pm
By Remcon
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
Bug in will_fall( )
Oct 23, 2017, 1:35 am
By GatewaySysop
Bug in do_zap( ), do_brandish( )
Oct 18, 2017, 1:52 pm
By GatewaySysop
Bug in get_exp_worth( )
Oct 10, 2017, 1:26 am
By GatewaySysop
LOP 1.45
Author: Remcon
Submitted by: Remcon
LOP Heroes Edition
Author: Vladaar
Submitted by: Vladaar
Heroes sound extras
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.3
Author: Vladaar
Submitted by: Vladaar
Memwatch
Author: Johan Lindh
Submitted by: Vladaar
Users Online
CommonCrawl, DotBot, Yahoo!, Yandex, Bing

Members: 0
Guests: 15
Stats
Files
Topics
Posts
Members
Newest Member
477
3,705
19,232
608
LAntorcha
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » Codebases » SWR FUSS » 10 C Programming Questions: L...
Forum Rules | Mark all | Recent Posts

10 C Programming Questions: Long Winded Post
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
* #1 Dec 27, 2005, 3:40 pm
Go to the top of the page
Go to the bottom of the page

Stan
Fledgling
GroupMembers
Posts23
JoinedNov 19, 2005

10 questions about coding.
Happy hollidays everyone,
I should have asked these questions 2 years ago, but oh well.

I have come across many C tutorials over the last couple years.
I find that with every tutorial I read there are some concepts that I think are not explained well at all but then another tutorial makes that part of the language crystal clear.
There are still a few areas I am having trouble in, such as writing arrays, for loops, and case statements propperly.
I suppose I will move on to readingg and writing to a file after I finish learning about the basics.

I have limited vision and am stuck using a screen reader, which does make coding more difficult.
I have played around with code on and off for the last 2 years, and still feel that I don't know nearly as much as I should by now.
I don't expect any one person to answer all these questions, I just figure itt would be a great help to many new coders who want to become proficient coders and hopefully contribute to the mudding community.

1. Why is it that some functtions use numbered case statements?
I thought case statements are great for menus, and that the correct way to use them is to have a case for every choice.
I see numbered statements used in the makearmor skill in swr1.0.
2. In the following for loop, why is obj used twice?
I am talking about the second instance of obj to tthe left of the second ;.
for( obj = first_object; obj; obj = obj->next )
3. What is a gsn, gsn_cook for example? I think it is used for holding a value from 0 to 100 showing how much of the specified skill the player has learned.
4. How do arrays work?
In the pcdata structure, there is the learned vvariable, and it has a [] which I believe makes it a variable holdingg a list of numbers.
5. What is the best known reference of standard C functions, by that I mean anything betwene printf and strcat to one_argument.
6. Can anyone recommend a tutorial on how to use valgrend?
I understand valgrend is a great tool for detecting memory leaks.
7. In the event a code starts out dicoo based and say 10 years later is totally diffferent and the code has been rewritten, what steps if any could be taken to get out of dealing with the dicoo licensing restrictions?
I figure one possible strategy would be to download the latest version of dicoo and see what its features are and gradually rewrite code they wrote.
8. Is it practical to have a 3d environment, you still have your normal exits, but each room has coordinates and sub coordinates.
Sub coordinates would be inside the room itself and would work about the same as the idea mentioned at Herne's smaug building site at the bottom of the ideas page.
It would be great to have the code parcially generate the description, maybe the first 3 lines of it, and then have builders fill in the details such as sound and sent if they wish.
I will not need any graphical components for this system as 30% of the players on my mud are blind anyway.
9. What is the easiest way to get the mud to delete a file?
I have a situation where ships are being built with cargo holds which save objects to a file, the file name is the same as the vnum, whenever the game loads up it loads the equipment and skips processing equipment in filenames nnamed after rooms that have been destroyed.
What happens is that someone will create a ship using some or all the destroyed ships vnums, causing the destroyed ships cargo to reappear anywhere the old vnum comes back into use.
10. What is the umin macro, and what is one example use?

Thanks in advance for the help.
       
Post is unread #2 Dec 27, 2005, 5:14 pm   Last edited Dec 27, 2005, 7:02 pm by Samson
Go to the top of the page
Go to the bottom of the page

Zeno
Sorcerer
GroupMembers
Posts723
JoinedMar 5, 2005

6. Here's a good tutorial on using valgrind:
http://www.muddomain.com/articles/valgrind.php
(Since the site is down, had to use a backup of it)

EDIT: URL corrected to proper site.
       
Post is unread #3 Dec 27, 2005, 6:29 pm   Last edited Dec 27, 2005, 6:41 pm by Remcon
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,858
JoinedJul 26, 2005

For number 10
ch->hit = UMAX( 1, ch->hit );
that would for example set ch->hit to at least 1 or ch->hit if its higher then 1
ch->hit = UMIN( 1, ch->hit );
that would set it for the lowest possible, if 1 is lower it gets set to 1, if ch->hit is lower it sets it to ch->hit.
Fairly simple thing :) (normaly for hit we would use UMAX)

For number 9
you can use remove or system just depends on what you want to do.

For number 7
This one has been discussed alot, unless you can totally get rid of all stock/modified stock functions its still bound to the old license. (I believe thats what has been decided)

For number 3
The gsn_(something) normaly hold the number places for skills/spells in the skill table. Take a look at assign_gsns.

For number 2
The first one is where you define it like obj = first_object.
The second is to limit it if you want, by putting obj it means as long as obj isn't NULL.
The third is to increase/change it like obj = obj->next.
if you remove the data in obj before it comes back around for the third one, you would use like
obj_next = obj->next; before the old obj is removed and all, and for the third one in the for loop
use obj = obj_next

Thats all the ones I'll answer heh, I'll let someone else answer those. (gives them something to do) lol
       
Post is unread #4 Dec 27, 2005, 7:41 pm
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,639
JoinedJan 1, 2002

Lets see.....

#7 - As the saying goes: "Once a Diku, always a Diku". There is only one way you can get out of the licensing restrictions for the codebase. Contact all of the involved authors and get their written permission to do so. Sicne this is unlikely to happen, you're basically stuck with it even if you do a 100% line for line rewrite of the code.

#9 - Easiest way would be to use the unlink() function to delete it. You will obviously want to put in some safetly checks as blindly unlinking files in linux is a one-way trip.

#6 - I will also add that the manual on valgrind.org is a good place to start.

#4 - You are pretty much on with arrays. Basically a list of numbers. Most often starting with array[0] and going up to array[n-1] where the array itself is declared as array[n]. Important to remember this. In C and C++ you cannot use the [n] element or it will cause memory overflows. You can only go up to [n-1]

#5 - Strangely enough, the standard C stuff like strcat, strcpy, sprintf, atoi, etc is decently explained by linux man files. Type in "man atoi" for example and you get a brief listing of which system header declared it, what the function declarations look like, the kind of arguments it expects, and what if anything it returns back. "one_argument" is not a standard C function so you should not expect to see that one listed. If you're not using linux, you might be able to get the same information from Cygwin if you have the man package installed with the manual pages.

#1 - Numbered switch statements are supposed to be a bit easier on resources. They're definitely less ugly than a mass of if/else checks. In a switch, the "default" case acts as a catch-all for any values not specifically asked for. So in makearmor, if ch->substate is not 1, and is not SUB_TIMER_DO_ABORT, the default case is used instead. You can probably see how this beats the pants off of a lengthy if/else check for every possible substate ( there are many ).
       
Pages:<< prev 1 next >>