Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
For prospective QC coders

#1
Here is a code example for prospective QuakeC coders, as well as some "interview questions" for it:

Code:
.string classname;
.string netname;

void func()
{
    entity e;
    e = spawn();
    e.classname = "foo";
    e.netname = "This ";
    e = spawn();
    e.classname = "foo";
    e.netname = "is ";
    e = spawn();
    e.classname = "bar";
    e.netname = "not ";
    e = spawn();
    e.classname = "foo";
    e.netname = "working.\n";

    for(e = world; (e = find(e, classname, "foo")); )
        print(e.netname);
}

And now the questions:

  1. What does func() output when nothing else has been run yet?
  2. Write the for loop as an equivalent while loop.
  3. What, do you think, may the three arguments to find() mean? What does find() return?
  4. What happens when calling func() a second time?
    1. Why does it do that?
    2. Doesn't this indicate some sort of memory leak?
    3. How do you suggest fixing it?

If you can figure this out without knowing QuakeC, you may be a good match for our team! Smile
BRLOGENSHFEGLE (core dumped)

The Bot Orchestra is back! | Xoylent Easter Egg | 5bots1piano
My music on Google Play and SoundCloud
Reply

#2
Okey, I'm probably completly wrong, I got only a very tiny experience with coding. and that was with Lua. But I'll try! Smile

1. Nothing.
2.
Code:
while (e = world; (e = find(e, classname, "foo")); )
     print(e.netname);
Oh, that's almost the same thing, I guess...
3. I think find does find what each variable is equal to or something, I don't know what it return though.

this was harder than i though -.-

4. no idea...

*ordering The C Programming Language (second edition) from amazon*
Reply

#3
None are correct. I will add ONE solution:

TO QUESTION 1:

It outputs:
Code:
This is working.
(with newline at the end)
BRLOGENSHFEGLE (core dumped)

The Bot Orchestra is back! | Xoylent Easter Egg | 5bots1piano
My music on Google Play and SoundCloud
Reply

#4
Lol, I misunderstood that... fuu, amazon have 20 day shipping. Sad
Reply

#5
I only know normal C. I guess spawn() works like the C++ new() and puts a data object on the heap, and "entity e;" only puts a pointer on the stack. Looks like each heap element has a reference to the previously created element. So:

1) "This is working."
2)
Code:
e = world;
while(e = find(e, classname, "foo"))
        print(e.netname);
3) arg1=list start element; arg2=class member to compare with arg3. find() returns a reference to the next element in the list that matches the criteria given by 2+3.
4) "This is working."
"This is working."
4.1) Because the list start element is world, and the first call already spawned 4 entities without removing them.
4.2) Not necessarily. Since the spawned elements can always be retrieved by a find with "world" as starting point, they might be used by other functions. If it is not intended, further calls to func() will finally deplete the heap and further spawn() will fail.
4.3) If the entities are not used by other functions, func() should remove() them at the end.
Reply

#6
(08-01-2012, 07:49 AM)machine! Wrote: Lol, I misunderstood that... fuu, amazon have 20 day shipping. Sad

QuakeC and C share a similar syntax, but you won't learn QC from a C book. In fact, you don't need to know any C to learn QC.
Reply

#7
Okey, but I've already order it.

EDIT: 4. I guess it outputs:
Code:
This is not working
Reply

#8
OOOOOOOOOOOOH GAMES GAMES GAMES

*grabs popcorn and watches closely*

p.s.: Good job Micha
Reply

#9
(08-03-2012, 11:46 AM)Samual Wrote: p.s.: Good job Micha

Thanks Smile
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  Chat / taunt HUD portraits (need help from other coders!) MirceaKitsune 12 17,629 03-26-2011, 11:04 PM
Last Post: Lee_Stricklin

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum software by © MyBB original theme © iAndrew 2016, remixed by -z-