When trying to debug my implementation of server.c, asking gdb to print out the variable line results in a <optimized out>.

(gdb) p line
(gdb) <optimized out>

After doing a bit of research with google, the value in a variable is optimized out if its never used again in the rest of the code. But it is still needed many times throughout the rest of the code, like:

strncpy(mthd, line, spc1 - line);
mthd[spc1 - line] = '\0';

So why is it being optimized out? Does the variable line have to be used in a particular way for it to not be optimized out? Or could it be a bug in the optimizer?

2 Answers 2


This is a bug in clang, which has been fixed in version 3.5. The CS50 team is working on getting an update out with update50.

  • Indeed, I tried compiling with gcc and the problem is gone.
    – Quevun
    Commented Mar 4, 2015 at 2:19
  • Is there an update coming soon? I'm working on server.c as well and this is an annoying issue. Anything I can do to fix? Compile with something else perhaps?
    – Richard
    Commented Jul 9, 2015 at 3:54
  • @Quevun It looks like this still isn't fixed. Can you tell me how you wrote the gcc command? I tried to use the same format as clang and it didn't work.
    – reddisht
    Commented Aug 17, 2015 at 21:40

As gitterb already said, this is most likely a clang bug.

To anyone still having this issue, you can use gcc to workaround it, at least for now.

Try to use a command like this one instead of clang in the makefile:

gcc -g -O0 -std=c99 -Wall -Werror ...

at the end of that, you would add the -o, likely the .c files, and -lcs50 -lm or any other libraries you need.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .