Hot answers tagged

19

The function "printf" was inherited by C from the B standard library. In B it wasn't the only such function, for example there was also a "printn" for printing numbers. See a reference for the language from an early unix version here: https://www.bell-labs.com/usr/dmr/www/kbman.html


16

Let's go back to the K&R roots: Origin In the tutorial chapter, on page 11 of original K&R, you'll find a hint on the origin of the function: By the way, printf is not part of the C language; there is no input or output defined in C itself. There is nothing magic about printf; it's just a useful function that is part of the standard ...


13

Maybe. The compiler might decide "hey, this function is only called a few times, and I'm supposed to optimize for speed, so I'll just inline this function". Essentially, the compiler will replace the function call with the body of the function. For example, the source code would look like this. void DoSomething() { a = a + 1; DoSomethingElse(a); } ...


11

In some languages, operators are not very special. Instead, they are merely functions with names made up of symbols, and often don't use the normal function call syntax. Lisp: Operators are just normal functions. (+ 1 2) adds its arguments, (< 1 2 3) checks for an ordering, …. There are no infix operators. There is nothing special about these names, and ...


7

It's about offsets. You have an address, which points to the location in memory where the array begins. Then to access any element, you multiply the array index by the size of the element and add it to the starting address, to find the address for that element. The first element is at the starting point, so you multiply the size of the element by zero ...


5

I know list questions are off-topic here, and that I shouldn't answer off-topic questions, but it's just so tempting! So, here are a number of languages I can think of off the top of my head that support first-class operators, or at least something similar: Apricot: (def plus +) Arc: (= plus +) Clojure: (def plus +) Common Lisp: (defvar *plus* ...


4

Yes, DSSSL was an inspiration behind CSS and XSLT.


4

Video players have what I call a "threshold of computation;" there exists a minimum level of data flow (for a given video resolution), below which a video player will not work at all (or will only work intermittently). To support writing a video player successfully, a programming language would most likely need: Relatively high performance, Bit ...


4

It's not the most basic printing function. The most basic printing functions would be puts and putchar which print a string and char respectively. f is for formatted. printf (unlike puts or putchar) prints formatted output, hence printf. For example it can print an int in hexadecimal, or a float rounded to three decimal places, or a string left padded. ...


3

This is a matter of implementation of the compiler or runtime (and its options) and cannot be said with any certainty. Within C and C++, some compilers will inline calls based on optimization settings - this can be trivially seen by examining the generated assembly when looking at tools such as https://gcc.godbolt.org/ Other languages, such as Java have ...


2

Because reducing the feature set of a language requires a compromise. Taking a feature out of the language means either: the language no longer has that feature, so people who need/value that feature will not want to use that language (aside: this is the reason I've never tried golang... while I like some of their ideas I find exceptions too useful to ...


2

You're looking for performance in the wrong place. The problem with function calls is not that they cost much. There is another problem. Function calls could be absolutely free, and you would still have this other problem. It is that a function is like a credit card. Since you can easily use it, you tend to use it more than maybe you should. Suppose you ...


2

I believe many functional languages treat operators no differently than any other function. An example of such a language is Haskell, where operators are essentially functions and can be passed in as parameters to other functions.


1

The statement "In (most? all?) programming languages, an index begins at zero" is simply not correct. Those languages whose heritage derives formally or informally from C follow this convention. Others may not. C did it that way because C was fundamentally intended to be a "high-level" assembler. It put a fair burden of the workload on the programmer, ...


1

I measured the overhead of direct and virtual C++ function calls on the Xenon PowerPC some time ago. The functions in question had a single parameter and a single return, so parameter passing occurred on registers. Long story short, the overhead of a direct (non-virtual) function call was approximately 5.5 nanoseconds, or 18 clock cycles, compared to an ...


1

That depends on how long time it takes to perform the overhead with the function call (setting up stack frame, passing variables, clearing up afterwards...) compared to time spent inside the function doing useful work. (Language, compiler and compiler setting dependent) Anyway, in order to actually notice this a significant time of the execution must be ...


1

I think it really depends on the language and on the function. While the c and c++ compilers can inline a lot of functions, this is not the case for Python or Java. While I do not know the specific details for java (except that every method is virtual but I suggest you to check better the documentation), in Python I am sure that there is no inlining, no ...


1

tl;dr; Yes, it is possible. But I doubt you will be able to support high-quality high-definition video. The performance of the decoding is not about it being "slow". It is about being able to support specific bitrates. If your decoder is slow, it can still play low bitrate video, but it will be unusable for higher bitrates. Video decoding is all about data ...


1

A compiled library calling a callback, which is a user defined member function of a user defined class. This is possible in Objective-C, and it makes user interface programming a breeze. You can tell a button: "Please, call this method for this object when you are pressed", and the button will do so. You are free to use any method name for the callback ...



Only top voted, non community-wiki answers of a minimum length are eligible