• Welcome to Valhalla Legends Archive.
 

Weird, is there anything wrong with this function??

Started by brew, July 23, 2007, 03:37 PM

Previous topic - Next topic

Zakath

If you really feel like getting technical, why not do the various instructions out in logic gates and do a real speed comparison?

Seriously, this bickering is totally pointless. Start doing something productive or this topic will be locked.
Quote from: iago on February 02, 2005, 03:07 PM
Yes, you can't have everybody...contributing to the main source repository.  That would be stupid and create chaos.

Opensource projects...would be dumb.

brew

#16
Quote
Hey, does anyone know of an atoi()-like function except is able to convert hexidecimal ? That'd be useful.

Just to let everyone know, I came across a function which was exactly what i was looking for-- sscanf();.
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

Yegg


/home/yegg> printf("%x", atoi ("123"))
7b


or


/home/yegg> printf("0x%x", atoi ("123"))
0x7b

brew

I ment hexidecimal input... like converting "35" to "5".
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

Barabajagal


rabbit

Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.

Barabajagal


rabbit

Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.

Yegg


/home/yegg> (char)0x35
5


That's how 35 becomes 5. He just wrote it wrong.

brew

Quote from: What's wrong with 現のさざ波? on July 27, 2007, 01:48 PM
that's not hexadecimal :(
Yes it is. I'm so sorry your brain automatically assumes a number is decimal, especially when I just asked about converting string literals of hexidecimal numbers to a value.
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

Barabajagal


brew

<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

Barabajagal


Kp

brew: never use sprintf.  It is deprecated specifically because so many people get it wrong.  Use snprintf (or, if you are stuck on Windows, _snprintf, but watch out for the different semantics from a proper snprintf).

The return type of malloc is void* because you can cast the result to any type, as documented in the manual page.  If you are using C++, you would be better served with using new / new[] so that you get the right type automatically.  For beginners, it is best to minimize the number of casts.  As you saw, they can override useful warnings and even make incorrect code build.

Avoid functions which allocate memory and then return a pointer to it.  Although they can be used correctly, many people will use them incorrectly, leading to memory leaks.  UserLoser already recommended a construct that would leak memory.  (Note: sometimes, this method is the most expedient way to solve a problem.  Functions which return an allocated structure are also necessary for certain design patterns.  In such cases, be sure to tag the function with __attribute__((warn_unused_result)).)

With regard to the efficiency of comparison: recall that on x86 processors, the jump instruction is not the instruction which computes the relation of the operands.  That is done by a prior instruction.  The jump instruction reads the eflags register to get the results of the comparison, and alters code flow accordingly.  Also, while there is technically some value in having the most efficient code possible, the speed with which a jump instruction can be processed makes the distinction between the various versions of jump largely irrelevant.  You have spent more time arguing the point than will ever be regained by having chosen the faster one (whichever one is faster, if they even have a speed difference).
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!