Bloomberg LP Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

Sunny, please only place REAL interview question here. This question is not stated correctly. If you don't declare a function "inline", how can a C++ compiler treat a function(even it is small) as inline? Did you get an interview and remember the question correctly?

- kulang July 31, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

the question is absolutely correct. merely specifying function as inline doesnt make it inline. you can only hint the compiler to make it inline. as others pointed, following are the scenarios in which even when specifying a func as inline wont make it inline.

1. when using resursion
2. when using loops inside functions
3. when taking function addresses

- AK August 01, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Recursion ?

- ibnipun10 August 01, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

AK is right

- sunny August 04, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think also virtual functions can't be made inline.

- Aleks August 05, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Inline function is a way to achieve inline expansion and the keyword inline is a programmer term to "advise" the compiler to consider for the inline expansion:

Advantages: The lifecycle of function call takes resources in calling, allocating and deallocating and generally the present day compiler are well equipped to support this in an optimized way. It is also considered that this advise of programmer in the language to inline expand a function is at the discretion of compiler optimization strategy.

Coming to have a opinion for this question that when will the compiler reject this advise,ps. not big code,

Reasoning: what makes an inline expansion to a non deterministic way.

1. expansion of a recursive function who return values depend on highly recurred run time parameter. Compiler will go crazy and will say bye bye to inline

what else,
2. Big loop. for the same reason.

3. Calling another function, compiler cannot find all the dependent functions nature as inline expansion. Of course its possible but huge overhead.

Thanks AK,

[WIKI]: " it is not always possible to inline a subroutine. Consider the case of a subroutine that calls itself recursively until it receives a particular piece of input data from a peripheral. The compiler cannot generally determine when this process will end, so it would never finish inlining if it was designed to inline every single subroutine invocation. Thus, compilers for languages which support recursion must have restrictions on what they will automatically choose to inline."

- yogeshv.info August 06, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The compiler cannot inline a function if:
The function has a variable argument list;
is recursive;
is virtual (direct calls to virtual functions can be inlined);
uses inline assembly, (unless compiled with /Og, /Ox, /O1, or /O2);
if the program takes the address of the function and the call is made via the pointer to the function (direct calls to functions that have had their address taken can be inlined);
the function and the caller use different types of exception handling (C++ exception handling in one, structured exception handling in the other).

- blueskin.neo November 21, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I must say that this is an out-of-date question. Nowadays compilers and linkers will inline and not inline whenever they feel like it, even the same function! Herb Sutter's 'Exceptional C++ Style', page 190 has a question: "3) .. What kinds of functions are guaranteed never to be inlined?" And his answer is 'none'. And this book is copyright 2005. (Sutter is both head (I think) of MS's compiler project, and of the C++ standard committee.) Now, whether the /compiler/ (and not the linker) will inline stuff, I can only think that it'd have to be when a function is 'extern' to a compilation unit. But, this is uninteresting, since the linker can still do it. So the only answer worth knowing is 'no'. Unless you happen to know your compiler's limits and quirks, but then that's not a generic C++ question.

- JeffD January 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

pointer to the inline function

- rockycharm November 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

pointer to the inline function

- rockycharm November 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

ya..if we define a function outside the class wer it is declared,compiler will not treat this function as inline..

- xclamation! July 31, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Maybe when the address of this function used anywhere?

- fiddler.g July 31, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Nope - Sutter's 'Exceptional C++ Style' says, pg 192: "It [inline] doesn't affect other parts of the standard language, in that writing 'inline' on a function does not change how you use the function (for example, you can still take the function's address) ..."

- JeffD January 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

// Try this code and look at the generated assembler ;)

void test() { }

void main()
{
void (*testFunc)() = test;
testFunc();
}

- fiddler.g January 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
-2
of 2 vote

constructor cannot be inline

- jiawei March 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

chutiya sale.

- aditya June 23, 2011 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More