His language requires O(n) time to get the length of a string

>his language requires O(n) time to get the length of a string
Cniles will unironically defend this

Attached: 1552022246609.jpg (905x957, 168K)

Other urls found in this thread:

en.wikipedia.org/wiki/Dynamic_array
twitter.com/SFWRedditGifs

If getting the length of a string is a bottleneck in your program, then you store the length somewhere instead.

/thread

This.
That leaves only one byte overhead for the null terminator

FPBP

>you store the length somewhere else instead?
Like... in a data type associated with the string so you can call string.length() on it?

Almost as if this should be built into the language or something...

but it is, but only when there's no overhead/abstraction.

int arr[16];
printf("%d\n", sizeof(arr)/sizeof(arr[0]))

C isn't for programmer convenience

yes it is. it keeps us from writing hardware-tailored machine code. it just has different priorities from other languages.

Attached: cniles_will_defend_this.png (1102x657, 87K)

It's worse than that. C doesn't even have strings. You need an external library or to roll your own

>C doesn't have strings
const char *x = "This is some string";

That's strlen(x) * 8 many bits of memory allocated for a string. That's literally what strings are. The meat of a std::string is still a char* when you call .c_str()

What is this even saying? Hurr durr pointers exist? Pointers exist in a lot of languages. Difference is language have beginning and end pointers. A data type that C is lacking
C does not include strings in the standard library

>char pointer is a string
Wrong

It's a pointer to the beginning of char allocated memory space, which is a string, you pedantic unemployed faggot

It is, you idiot

>He can't into Pascal strings.
>On Jow Forums
kys faggot.

>what are structs

>implying arr won't be cast to void* by some other function at some point
I like your optimism user

Attached: images.jpg (248x203, 5K)

>Difference is language have beginning and end pointers
>want string of some length
>request memory block of some length
>get pointer to beginning
>decide I'd like the exact length stored with the string
>store length at the first address
>or store a pointer to the end at the first address
>or make a struct that can hold the string, its length, and whatever else I want, including functions
It's almost like instead of implementing a million things poorly you may or may not need, C gives you the tools to implement something the way you need it.

typedef struct string{
char *str;
unsigned len;
}string;

there you go, now its up to you to manage the memory

I mean by that criteria everything is a gadget so you might as well say DaTa tYpEs dOnT eXiSt aT aLl

What's "dynamic arrays" ?
The "quality" of programmers on this board summed up in one of the most retarded fucking shit posts I've ever seen.
Find yourself another career path pajeet.

you dont know what dynamic arrays are user?

Answering the question posed with the same question...
>kys faggot.

>...
do you need to go back user?

en.wikipedia.org/wiki/Dynamic_array
Hopefully that clears it up for you user. Dynamic arrays can be tricky if you're a simpleton. If you're implying that you can't use dynamic arrays in C, then I'm afraid you're retarded. They're quite simple.

I wasn't asking you fucking imbecile.
I guess reading and understanding context is beyond the fucking simpletons in here.

>cant understand arrays or pointers
no one will ever find anything of worth here, we can all go home, Jow Forums is just shitposts

Dynamic arrays are dynamically allocated arrays user, either allocated on the heap, or as variable length arrays, on the stack. VLAs can't change size once they are made however.

user, you're the retard here.

If you use strlen, you're actually doing something wrong...

The funny thing is I think that meant "What are 'Dynamic Arrays', as in if you were to use one you wouldn't have to 'manage the memory'.

If that is the case, and he is conflating memory management with making sure the array is big enough, he's the fucking retard.

This isn't 1973
Not all characters are 8 bits.

What is UTF8

In C you manage memory yourself.

I think he is just retarded.

C is for fast portable low level code. if you value programmer time more than anything else, you won't be having them use C

Based

Of you have nulls inside your string and don't have a length stored somewhere, you have larger problems.

>That's strlen(x) * 8 many bits of memory allocated for a string
I bet your code segfaults a lot.

A char pointer is a char pointer. A string is a string. There are obvious differences between the two if you've programmed in a language that actually has strings

How are strings implemented in other languages?

What programming languages actually do this?

are strings in other languages not arrays of characters under the hood?
are they linked lists of characters?

>are they linked lists of characters?
only in awful functional languages

>strings are linked lists of characters in functional langs
w-why

Attached: 00000000000001.png (300x490, 59K)

C

it fits the functional paradigm more despite being inefficient as fuck
something to do with currying or immutabilty probably

>C has strings
Wow! Cool thread btw.