Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22148

Why are gcc and clang not hoisting strlen out of this loop?

$
0
0

Consider the following code:

#include <string.h>void bar(char c);void foo(const char* restrict ss) {    for (int i = 0; i < strlen(ss); ++i) {        bar(*ss);    }}    

I would expect the strlen(ss) to be hoisted out of the loop in these essentially ideal conditions; and yet - it isn't, neither by clang 5.0 nor by gcc 7.3 with maximum optimization (-O3).

Why is this the case?

Note: Inspired by (my answer to) this question.


Viewing all articles
Browse latest Browse all 22148

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>