Qualcomm Interview Question






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

Normally the compiler compiles the code in 1/2 passes. i.e. it goes through the code and gives out the corresponding assembly/binary. Code optimization is one of the stage involved in the compilation. At the time of code optimization, the compiler tries to reduce the memory fetch cycles (CPU <----> RAM Read /Write cycles) in order to increase the execution speed of the program when executed. So mostly it is assumed by compiler that a variable is only modified by the CPU operations and no other entity is modifying the variable . So compiler simply removes reading of a frequently used variable from system memory/RAM. But there are cases when the variable allocated in RAM/ System memory is modified by external units such as, in industrial automation various sensors e.g. flow sensor gives out data frequently, once per 10msec. If a variable read of such memory locations are optimized and read only once after program load than sensor data will be erronous. Thus, such memory locations are marked as volatile to avoid any optimization and to read always from the main memory.

- Devendra Vaja December 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

if a variable is preceded with volatile keyword then compiler will try to put the variable in a register to reduce the amount code of loading and storing the variable

- rajeshbabu January 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Wrong

- Amit July 19, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

That's register

- rrr March 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

That's register

- rrr March 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

volatile is a qualifier of an integer which is just a hint for the compiler to suggest that this piece of storage will be modifies frequently .
Compiler may comply and put it in a CPU register .

- Anonymous January 25, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

wrong

- Amit July 19, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

It also suggests that the compiler should switch off any optimizations for the variable. i.e if the variable is loaded to a register and the register isn't modified, for the next access of the variable it picks it from the memory instead of using the old register value. (A different thread might have modified the variable)

- Anonymous January 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Volatile variables never get into register.
Problem is how do threads know about each other using value.

They are specially used in embedded system program, value can be modified externally.

- Amit July 19, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

volatile is the type specifier not the storage specifier. Any variable declared as volatile can be modified by other processes, threads, and some external agents like interrupts without the permission of the declaring process.

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

volatile is a type qualifier like const.

- vatz May 26, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Volatile keyword will instruct the to compiler not to optimize the variable in function. When ever value of this variable is used, it is read from the memory to get the current value

- gopi July 30, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Volatile is a type qualifier. It says to the compiler that the variable declared as a volatile changes in unpredicted ways and every read and write to the volatile should be a load or store to the variable in the same order in the executable code.
Use of volatile:
Reading H/w registers

- vatz May 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Volatile :
A variable that is subjected to change externally is declared with the keyword volatile. By Declaring it volatile , you are informing the compiler to not perform optimization to the part of the code where variable is been used i.e to not rely on the value that is stored in cache for that variable rather go to the memory and get the value for the variable by performing load and store instructions.

- Rajeev Sawant January 11, 2018 | Flag Reply


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