User Name:


Forgot your password?
Vote for Us!
Nov 28, 2018, 10:10 am
By Keirath
First Immortal
Oct 12, 2018, 12:02 pm
By GatewaySysop
Bug in do_climb( )
Jun 5, 2018, 5:31 pm
By joeyfogas
question on overland code
May 31, 2018, 10:03 am
By joeyfogas
KaVir's Protocol Snip
May 15, 2018, 7:57 pm
By joeyfogas
tintin++ ogg sound player script for linux
Author: Robert Smith
Submitted by: Vladaar
6Dragons ogg Soundpack
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.4
Author: Vladaar
Submitted by: Vladaar
LoP 1.46
Author: Remcon
Submitted by: Remcon
LOP 1.45
Author: Remcon
Submitted by: Remcon
Users Online
CommonCrawl, Yandex

Members: 0
Guests: 17
Newest Member
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

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

JoinedMar 5, 2005

6. Here's a good tutorial on using valgrind:
(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

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

Black Hand
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 >>