Sponsored Content
Top Forums Programming 'strlen' of a constant string Post 302227326 by TriKri on Thursday 21st of August 2008 04:06:14 AM
Old 08-21-2008
What about the runtime of strlen taken on constant strings instead of 'ordinary' strings? Shouldn't the compiler be able to tell the string's length during compilation and replace the strlen call with that value?

For example, if I write strlen("1234567890"), will the compiler replace it with (size_t)10, or will strlen be called every time that line is executed?
 

7 More Discussions You Might Find Interesting

1. Programming

Problems with Strlen

hello, i have a problem with strlen. I have written this: for(y=13,z=0; cInBuf!=' ';y++) { cBuf=cInBuf; z++; } len = strlen(cBuf); out=len/2; fprintf(outfile,"F%i",out); If strlen is e.g. 22, it write F22. I want to write F2F2. How can i do this?... (5 Replies)
Discussion started by: ACeD
5 Replies

2. Shell Programming and Scripting

choose random text between constant string.. using awk?

Hallo I have maybe a little bit advanced request.... I need to choose one random part betwen %.... so i have this.. % text1 text1 text1 text1 text1 text1 text1 text1 text1 % text2 text2 text2 text2 text2 % text3 text3 text3 tetx3 % this choose text between % awk ' /%/... (8 Replies)
Discussion started by: sandwich
8 Replies

3. Programming

strlen for UTF-8

My OS (Debian) and gcc use the UTF-8 locale. This code says that the char size is 1 byte but the size of 'a' is really 4 bytes. int main(void) { setlocale(LC_ALL, "en_US.UTF-8"); printf("Char size: %i\nSize of char 'a': %i\nSize of Euro sign '€': %i\nLength of Euro sign: %i\n",... (8 Replies)
Discussion started by: cyler
8 Replies

4. Shell Programming and Scripting

Trouble appending string constant to variable

Hi. I define my variables as: month=jul DD=17 YEAR=2012 transmission_file_name_only=test_$month$DD$YEAR_partial.dat However when I run my script the variable 'transmission_file_name_only' resolves to: File "/downloads/test_jul17.dat" not found. How can I append this '_partial'... (3 Replies)
Discussion started by: buechler66
3 Replies

5. Shell Programming and Scripting

How to solve awk: line 1: runaway string constant error?

Hi All ! I am just trying to print bash variable in awk statement as string here is my script n=1 for file in `ls *.tk |sort -t"-" -k2n,2`; do ak=`(awk 'FNR=='$n'{print $0}' res.dat)` awk '{print "'$ak'",$0}' OFS="\t" $file n=$((n+1)) unset ak doneI am getting following error awk:... (7 Replies)
Discussion started by: Akshay Hegde
7 Replies

6. Programming

String Constant C

I wonder string constant exists permanently or temporary. For example, printf("hello, world"); the function printf access to it is through a pointer. Does it mean storage is allocated for the string constant to exist permanently in memory? :confused: (4 Replies)
Discussion started by: kris26
4 Replies

7. Programming

Segment fault related to strlen.S

Hello, This function was copied into my code, which was compiled without error/warning, but when executed there is always Segmentation fault at the end after the output (which seems correct!): void get_hashes(unsigned int hash, unsigned char *in) { unsigned char *str = in; int pos =... (7 Replies)
Discussion started by: yifangt
7 Replies
STRING(3)						   BSD Library Functions Manual 						 STRING(3)

NAME
index, rindex, stpcpy, strcasecmp, strcat, strchr, strcmp, strcpy, strcspn, strerror, strlen, strncasecmp, strncat, strncmp, strncpy, strpbrk, strrchr, strsep, strspn, strstr, strtok -- string specific functions LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <strings.h> char * index(const char *s, int c); char * rindex(const char *s, int c); int strcasecmp(const char *s1, const char *s2); int strncasecmp(const char *s1, const char *s2, size_t n); #include <string.h> char * stpcpy(char *dst, const char *src); char * strcat(char *restrict s1, const char *restrict s2); char * strchr(const char *s, int c); int strcmp(const char *s1, const char *s2); char * strcpy(char *restrict s1, const char *restrict s2); size_t strcspn(const char *s1, const char *s2); char * strerror(int errnum); size_t strlen(const char *s); char * strncat(char *restrict s1, const char *restrict s2, size_t n); int strncmp(const char *s1, const char *s2, size_t n); char * strncpy(char *restrict s1, const char *restrict s2, size_t n); char * strpbrk(const char *s1, const char *s2); char * strrchr(const char *s, int c); char * strsep(char **stringp, const char *delim); size_t strspn(const char *s1, const char *s2); char * strstr(const char *s1, const char *s2); char * strtok(char *restrict s1, const char *restrict s2); DESCRIPTION
The string functions manipulate strings that are terminated by a null byte. See the specific manual pages for more information. For manipulating variable length generic objects as byte strings (without the null byte check), see bstring(3). Except as noted in their specific manual pages, the string functions do not test the destination for size limitations. SEE ALSO
bstring(3), index(3), rindex(3), stpcpy(3), strcasecmp(3), strcat(3), strchr(3), strcmp(3), strcpy(3), strcspn(3), strerror(3), strlen(3), strpbrk(3), strrchr(3), strsep(3), strspn(3), strstr(3), strtok(3) STANDARDS
The strcat(), strncat(), strchr(), strrchr(), strcmp(), strncmp(), strcpy(), strncpy(), strerror(), strlen(), strpbrk(), strspn(), strcspn(), strstr(), and strtok() functions conform to ISO/IEC 9899:1990 (``ISO C90''). BSD
December 11, 1993 BSD
All times are GMT -4. The time now is 10:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy