[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
>C is a good language >strcat and strcpy exist
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 101
Thread images: 5
File: 1450029603452.gif (2 MB, 206x223) Image search: [Google]
1450029603452.gif
2 MB, 206x223
>C is a good language
>strcat and strcpy exist
>>
It’s called managing pointers correctly you retarded sub-mongoloid.
>>
>>51985119

> complaining about functions that they're not forced to used
> not picking on an actually useless function like gets instead
>>
>>51985165
:^)

it's ok when dennis richie does it
>>
>>51985119
What's wrong with those functions?
>that gif
What the fuck is this?
>>
>>51985443
>What's wrong with those functions?

My thoughts exactly. How do functions for simple convinience make a language bad?
>>
>>51985443
Buffer overflows

GIF:
https://www.youtube.com/watch?v=WDAqx3LZQpQ
>>
>>51985443
not safe. any char that gets put through those functions without a null terminator are subject to buffer overflows
>>
>>51985537
>any char that gets put through those functions without a null terminator are subject to buffer overflows

Solution: dont put through any char without a null terminator.
>>
>>51985537
>if I put something in a function, it does exactly what it says it will do
>therefore it's bad

You java cucks piss me off.
>>
>>51985501
>>51985537
It's not those function's fault you have broken strings.

Also, there's a safer alternative, strncat and strncpy, both were added in C99 if I recall correctly.

Also, string support in C standard library is shit anyway, use some unicode library.
>>
>>51985119
C is "good" but is very rudimentary and basic , you have to do everything yourself.
Also , you should just use strncat and strncpy
>>
What libraries make C good like Python?
>>
Why aren't you ooping in C?
http://libcello.org/
>>
>>51985443
http://www.besiege.spiderlinggames.co.uk/
>>
>>51986021
>transforming C into an oop abortion instead of using a language that was designed with oop in mind
>>
You should be using string objects anyway. The extra 3 bytes aren't a problem on modern systems. Rolling your own string library with them is pretty easy.
>>
>>51986021
What the hell is this abomination
>>
C++ with operator overloads is a lot easier to read and it is just as efficient.
>>
>>51986021
This is pretty neat. It's like a mix of C, JavaScript and PHP.
>>
>>51986021
>http://libcello.org/
I am. But instead of using some library for that I design my applications in OOP manner and then use structs + functions to implement that. I just wish they would add anonymous struct declarations inside other structs to a standard. That would allow for poor-man's inheritance.
>>
>>51986021
var prices = new(Table, String, Int);
set(prices, $S("Apple"), $I(12));
set(prices, $S("Banana"), $I( 6));
set(prices, $S("Pear"), $I(55));

Why tho?
//C#
var prices = new Dictionary<string,int>
{
["Apple"] = 12,
["Banana"] = 6,
["Pear"] = 55;
};

Look at all that extra shit you don't have to write, or have your finger twitching on the shift key.
>>
>>51986902
In C you can just write a macro and be done with, can't do that in C# though.
>>
>>51986984
That set is a macro. And plus you'd have to include the $S(), $I() for strings and ints.

Plus, I'd like to see a macro that can take an arbitrary number of elements and set them.

In C#, this just goes ad infinitum
var prices = new Dictionary<string,int>
{
["Apple"] = 12,
["Banana"] = 6,
["Pear"] = 55,
["You"] = -3,
["Me"] = 700,
//.....
};
>>
>>51985625
I think you mean someone else. I was just giving the reason why people that use C dont like those functions.

Besides, people with any proficiency in C would have rewritten most of the standard libraries to suit their preferences anyway.
>>
>life is precious
>op exists
>>
>>51985537
> i dont know how to write code without safety nets
> nobody else can either

Holy shit I bet you think all languages should use a garbage collector too.
>>
>>51985263
There are no better alternatives to string handling than strcat and strcpy, you fucking retard.
But you are right, I am not forced to use C.
>>
>>51985537
No, the reason they are bad is because they make something trivial as manipulating strings unnecessarily complicated.
>>
>>51986236
I like this post.
>>
File: iu-252.jpg (8 KB, 142x200) Image search: [Google]
iu-252.jpg
8 KB, 142x200
>>51986021
oop in loo pajeet
>>
>>51986902
Wow, even in C# it looks like something from a century ago. Shameful if you consider C# was created after Javascript.

var prices={Apple: 12, Banana: 6, Pear: 55};
>>
>>51985119
>pythonbabby cant find his black box string functions
-strings are a numeric type in C
-strings are used as types that are able to describe bare metal bit patterns exactly
-strings are handled in arrays in C and can be cast to other types, bit masked, and handled in pointers

pythonbabbys need to stop running their mouth off about things they dont have a clue about
>>
>>51989144
>-strings are used as types that are able to describe bare metal bit patterns exactly
Yes, in any language other than C.
C must be the only language where you have to jump through various hoops if you want to handle strings with zeroes in them. A++, would not use again.
>>
>>51988967

https://github.com/msteinert/bstring
>>
>>51989202
>strings with zeroes in them
'0' != '\0'
>>
>>51989216
You don't say. Thanks for this useless contribution.
>>
>>51985119
You do realize that the standard C library is not part of the C language itself? Fell free to reimplement any needed/desired functionality yourself as you see fit if you aren't happy with whatever the available libraries provide.
>>
>>51985537
With power comes responsibility. C allows you to do pretty much anything you want, but you need to know what you're doing in the first place. Are you going to complain next how kitchen knives are bad because you can cut yourself if being clunky and/or uncautious while using them?
>>
>>51986021

Too lazy to actually dig into the source code, but there have been dozens of C libraries based on type-punning. Unfortunately, all of those libraries are not standard C99 and above and break under strict aliasing rules.

The ONLY way you're allowed to do anything OOP-related in C is to abuse the fact that you can cast a struct to the type of its first member and vice versa.
>>
>>51989202
Assuming by "zeroes" you mean NUL chars, well, they serve as string terminators in C, thusly anything beyond a NUL char is not part of the same string anymore. Besides, they don't yield a graphic character in any encoding I could think of, why would you want to have NULs embedded within a string anyway? C has worked that way since over four decades and your whining about it isn't going to change much I think.
>>
>>51989549

If you are dealing with strings in C and you're not using a string library like https://github.com/msteinert/bstring that uses a length/data struct, you are a fucking idiot and probably shouldn't be writing C.
>>
>>51989235
Thanks for your useless existence.
>>
>>51985119
>not using memcpy
its like you hate performance or something
>>
>>51989235
if you want to deal with a non-null-terminated string (e.g. binary data), then deal with it, it's not fucking hard
>>
>>51989673
No, it's not hard. Assembler is not hard either, it's so simple even a retard could learn it.

But it's a waste of time. While you're busy massaging your strings just in the right places, I'll have completed the entire application.
>>
C is an ok language as far as approximating the rough Von Neumann model of imperative computation is concerned. However the question of why people write programs as if they are some kind of robotic machine as opposed to a creative individual is a mystery when there are perfectly good functional and relational languages to use.
>>
>>51989118
A pear wouldn't be that expensive though. Can you consider a language truly modern if it allows you to enter unrealistic prices for fruit?
>>
>>51989549
>why would you want to have NULs embedded within a string anyway?
Did you even read the post I was replying to? Binary data tends to have those once in a while.

>C has worked that way since over four decades and your whining about it isn't going to change much I think.
Nor is there any need. C has long ceased to be relevant.
>>
>>51988967
sprintf makes everything you can possibly want.
>>
>>51989939
>The language OS's are still written in
>Shader and GPGPU code is a an expanded subset of it
>The programming language of choice for embedded use
>Somehow irrelevant
Sure, in user applications it's been surpassed by C++ for applications where performance matters and other newer languages, but it's still very widely used in many applications.
>>
>>51990001
Except print structs, huehue. Which works with most modern languages with printf-equivalents. They don't even make me guess buffer sizes in advance.
>>
>>51989939
>>why would you want to have NULs embedded within a string anyway?
>Did you even read the post I was replying to? Binary data tends to have those once in a while.
and why the fuck do you want to use string functions on binary data ?
>>
>>51990204
my thoughts exactly.

>C has long ceased to be relevant.
sure.
>>
>>51990204
See, that's entirely the problem. In other languages there's no reason to give a flying fuck about any of that, because there's no difference between binary data and "normal" strings. As it should be.
>>
>>51990317
> In other languages there's no reason to give a flying fuck about any of that, because there's no difference between binary data and "normal" strings. As it should be.
can you give any examples ?
>>
>>51990040
sprintf isn't magic, it's just for string manipulation, if you want to print structs, you have to define it's print method, structs are just bytes.
[CODE]
typedef struct
{
float x, y;
} Dragon;
Dragon *Dragon_new(float x, float y);
void Dragon_free(Dragon *);
void Dragon_fly(Dragon *, float speed);
void Dragon_print(Dragon *);
[/CODE]
>>
>>51990348
I sure fucked that up:
typedef struct
{
float x, y;
} Dragon;
Dragon *Dragon_new(float x, float y);
void Dragon_free(Dragon *);
void Dragon_fly(Dragon *, float speed);
void Dragon_print(Dragon *);
>>
>>51990348
I know. Point being, in other languages it you can have that magic. When you feed an object to printf, it just calls the object's toString() method, which easily saves you one or several lines of code.
>>
>>51990317
what the fuck are you talking about? how is there a difference between binary data and strings in C? the only reason there are string functions is to make working will \0 terminated text easier - there is literally no factual distinction.

whereas in python, as an example, there is a grave difference between a string and a bytearray (which is admittedly a bit apples and oranges, but still an annoyance when working with byte sized binary stuff)
>>
>>51990317
>>51990347
still waiting
>>
>>51990452
and who implements the objects toString() method ? its not like the language/compiler magically writes it for you
>>
>>51990452
wtf, writing Dragon_print(dragon) is somehow much longer than System.out.println(dragon); ??
>>
>>51990347
An example of what? Languages? To which I would answer: can you give a counter-example?
Pretty much no popular language gives special treatment to nul characters: it's true for Java, C#, C++, Python, PHP, Javascript, etc.
>>
>>51990458
i thought he meant that in other languages string functions work on binary (continaing NULL bytes and non printable characters)data
>>
>>51990541
do you have any fucking idea what you are talking about ?
and the language examples is probably the most retarded thing i've read on 4chan in a while
>>
>>51990541
I don't see that as a positive, not having to worry about something seems way too similar to what a father would say to his retarded offspring. It's an euphemism for "I won't give you the power to do something"
>>
>>51990458
>the only reason there are string functions is to make working will \0 terminated text easier
Are you dense? \0 terminated strings are an invention of the C realm, it's a construct that other language simply do not need - that's why there is no need to differentiate.

>>51990495
? The toString() implementation is not the problem, its invocations are.
>>
>>51985119
You don't have to use them, you fucking faggot. >>51989909
yeah i'll just write my next OS in fucking prolog
>>
File: down.jpg (85 KB, 611x429) Image search: [Google]
down.jpg
85 KB, 611x429
>>51990603
Instead of being honest and saying:
>Don't touch that, your retarded ass is gonna break that shit.
He goes:
>You don't have to worry about it, come, enjoy implicitly heap allocated strings.
>>
>>51986238
I wish namespaces existed in C
>>
>>51990645
>? The toString() implementation is not the problem, its invocations are.
how does the invocation
>easily saves you one or several lines of code.
how the fuck can you spend one or more lines of code on the C style invocation that you couldn't in the C++ or Java one?
>>
>>51990579
>do you have any fucking idea what you are talking about ?
Far more than every other user on this board combined.

>and the language examples is probably the most retarded thing i've read on 4chan in a while
Tell me more! When you speak with this much conviction it should surely be easy for you to elaborate on your point.


>>51990603
Please don't embarrass yourself. Try to formulate what exactly that power is that those languages supposedly remove. What they really remove is a pointless limitation of C.
>>
>>51990699
but_it_does_comma_anon
>>
>>51986187
I just wish you could define your own operators and that it'd copy some of the typesystem in haskell.
implementing a C++ operator is really tedious, compared to implementing a typeclass in haskell.
Also being limited to the base operators that C++ provides is a pain.
>>
>>51990645
i'm aware it's an invention of the C realm. are you aware that most other languages simply have some kind of sugar on top of strings making them objects or preconfigured data types (with the latter oftentime boiling down to "char array with \0 at the end")?

your post makes me think you don't really understand the concept of low level programming and data representation very well.
>>
>>51990724
>how the fuck can you spend one or more lines of code on the C style invocation that you couldn't in the C++ or Java one?
Except you can. In the case of C++, it does not have a printf equivalent in the standard library, but a superior one can be build with variadic templates.

>how does the invocation
Wastes time and space. Seriously, do I speak in riddles or why does it take like ten posts for a simple point to get across?
>>
File: 1428232649893.gif (397 KB, 245x138) Image search: [Google]
1428232649893.gif
397 KB, 245x138
>>51990850
>easily saves you one or several lines of code.
Object_print(object);
System.out.println(object);
std::cout << object;
>easily saves you one or several lines of code.
>>
>>51990850
Actually, variadic isn't a good C++ practice, people instead, you should overload the << operator. Which would give you the functionality you want, whilst at the same time obfuscating the code.
>>
>>51990848
>with the latter oftentime boiling down to "char array with \0 at the end
No, just no. It may be hard to grasp the concept for someone who lives in his little C world, but elsewhere the world does not end with \0. Strings are organized as character sequence/length pairs.

>your post makes me think you don't really understand the concept of low level programming and data representation very well.
How cute.
>>
>>51990942
In C, if you see you can increase performance, you do pair up the char sequence with it's length, although you are wrong to say elsewhere in the world not ending with \0, because almost everything in the computer works like that, files work like that, sockets work like that. When working with low level sockets, I find it very useful to be talking the same language when coding and when sending data.
>>
>>51986902
that c# syntax is ass m8

var prices = new Dictionary<string, int> 
{
{"Apple", 12},
{"Banana", 6"},
{"Pear", Girlfriend.Age()}
}
>>
>>51990926
Which requires you to deal with the standard C++ streams, which might be one of the greatest design failures in the history of computer science.
Either that, or you use alternatives and accidentally end up with code that's shorter, more clear and has five times the performance than anything that involves ostream and company.
>>
>>51985119
That's why you use strncat and strncpy n00b.
>>
>>51990905
Hey now, please don't go bullshit mode on me. I see no printf in there, so do it again.
>>
>>51990982
>files work like that, sockets work like that
You're talking about serialized data layouts, it has nothing to do with sockets and files.
C doesn't give you any particular advantage when parsing data that contains null-terminated strings.
>>
>>51990364
You still screwed it up

> void Dragon_print(const Dragon* const)
>>
>>51991922
;
>>
PROTIP: C "strings" are not the same as Java/Python/Ruby/Perl/C++/C#/Swift/Go "strings"
>>
>>51985119
ITT: lots of people who have never even heard of the concept of array/ptr decay nor ever questioned why strings would ever be in-band terminated.
>>
File: 1450189306019.jpg (29 KB, 250x166) Image search: [Google]
1450189306019.jpg
29 KB, 250x166
>>51985119
>>
>>51990769
>Far more than every other user on this board combined
>>
>>51985627
This, you cuck.
>>
>>51990769
Soooooo b8 thread then?
>>
>>51985863
there already is a good library written in C called python.
you probably never heard of it
>>
>>51985119
>he doesn't know about strncat and strncpy
>>
>>51993988
>array/ptr decay
That sounds stupid lol, i bet it doesn't even exist.
>>
>>51994370
OP's point is probably that C strings are fucking retarded for any machine with more than 16kB of memory, and that they probably only even exist because arrays aren't even a true full type in the language.

> while (*p++ = *q++); // <-- billions of bugs induced just so this could be possible ...
>>
>>51994624
nice b8, m8.
>>
>>51985625
>Everyone should program in C so I can exploit the security vulnerabilites to hack the planet
What a noble goal, anon!
>>
>>51989118
Now tell me does your object have all the functions a dictionary in C# has?
Thread replies: 101
Thread images: 5

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.