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

snprintf occur different Performance [closed]

$
0
0

here is code:

while((nread = read(fd1,read_buf,sizeof(read_buf)))){                                               int ret = snprintf(write_buf,sizeof(write_buf),"%s",read_buf);                                          int vprintf(const char *format, va_list ap);    if(ret < 0){                                                                                 │       int  vfprintf(FILE  *stream,  const  char  *format,        perror("snprintf failed");                                                               │       va_list ap);    }else{                                                                                       │       int vsprintf(char *str, const char *format, va_list        write(fd2,write_buf,strlen(write_buf));                                                  │       ap);    }                                                                                            │       int vsnprintf(char *str, size_t  size,  const  char    printf("strlen:%d, nread:%d\n",strlen(write_buf),nread);                                     │       *format, va_list ap);    bzero(write_buf,sizeof(write_buf));                                                          │   Feature  Test  Macro  Requirements  for glibc (see fea‐    bzero(read_buf,sizeof(read_buf));                                                            │   ture_test_macros(7)):}  

If i dont use -O2,the second cycle strlen is 11,nread is 10; but if i use gcc -O2 ,strlen is 10,nread is 10. I dont konw why , please give me an answer. thank you!


Viewing all articles
Browse latest Browse all 22209

Trending Articles



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