TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Is C# a low-level language?

167 pointsby benaadamsabout 6 years ago

15 comments

MarkSweepabout 6 years ago
If you really wanted to, you can program in a subset of C# that is similar to C. You can avoid the garbage collector by using a native memory allocator and then manipulate pointers with the usual * and -&gt; operators.<p>While you probably don&#x27;t want to write a whole program like that, sometimes it is helpful to use these features when porting code from C or for performance reasons. See for example this implementation of memmove that is used for copying strings and other things:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;dotnet&#x2F;coreclr&#x2F;blob&#x2F;7ddd038a33977b152e856448443425cbc6b591c6&#x2F;src&#x2F;System.Private.CoreLib&#x2F;src&#x2F;System&#x2F;Buffer.cs#L183" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dotnet&#x2F;coreclr&#x2F;blob&#x2F;7ddd038a33977b152e856...</a>
评论 #19293704 未加载
评论 #19292366 未加载
评论 #19292049 未加载
slaymaker1907about 6 years ago
For those saying a GC is too high level, malloc is also a high level abstraction. There are relatively simple implementations of malloc, but allocators like jemalloc are starting to look quite a lot like a GC in the ways they manage memory.<p>The real issue with GCs is the lack of control that makes it very difficult if not impossible to do things like grouping allocations together. However, this capability comes at a cost since then you can’t move around existing allocations without going to extreme lengths and can easily lead to memory fragmentation.
int_19habout 6 years ago
This conflates the language, a particular implementation of that language, and a particular runtime that said implementation uses.<p>As far as the language goes, you can do anything in C# that you can do in C in terms of memory-unsafe programming - raw pointers, pointer arithmetic, unions, allocating data on the stack - it&#x27;s all there, and it&#x27;s not any harder to use. Since semantics are the same, it should be possible to implement it just as efficiently as in C. At that point, the only overhead that you can&#x27;t remove by avoiding some language feature or another is GC, although you can avoid making any allocations through it. So the real question is whether a language with GC can be considered low-level.
booleandilemmaabout 6 years ago
C# is managed code, so no, it’s not low-level by any reasonable definition of the term and calling it so would be confusing to anyone getting started in this stuff.
评论 #19292075 未加载
mcraihaabout 6 years ago
Unity is also going to do some C++ -&gt; C# conversions <a href="https:&#x2F;&#x2F;blogs.unity3d.com&#x2F;2019&#x2F;02&#x2F;26&#x2F;on-dots-c-c&#x2F;" rel="nofollow">https:&#x2F;&#x2F;blogs.unity3d.com&#x2F;2019&#x2F;02&#x2F;26&#x2F;on-dots-c-c&#x2F;</a>
评论 #19291472 未加载
fallingfrogabout 6 years ago
I remember back when they called C a high level language- because it wasn’t assembler. Yes, I’m old. But, my point is that there probably isn’t a definitive answer to that question that won’t change with changing technology.
评论 #19298114 未加载
评论 #19293264 未加载
0xTJabout 6 years ago
Some people say that C isn&#x27;t low-level (though I disagree). I personally don&#x27;t think of C# as even remotely low-level.
评论 #19291896 未加载
评论 #19291707 未加载
评论 #19291687 未加载
评论 #19292118 未加载
评论 #19293436 未加载
评论 #19292150 未加载
mooman219about 6 years ago
This has a click-baity title. A mostly math&#x2F;calculation heavy C++ program is translated into a mostly math&#x2F;calculation heavy C# program. You could replace either side with any language and get the same outcome. At best, the end of the article lists some hacks you _could_ write in C# to get what you consider &quot;low-level&quot;, but ultimately defeat the purpose of using a &quot;high-level&quot; language in the first place. If you&#x27;re using unsafe calls and platform intrinsics, it&#x27;s more than a one off situation, and the language doesn&#x27;t encourage it, then maybe you&#x27;re trying to hammer a nail with a shoe.
评论 #19286363 未加载
评论 #19293196 未加载
评论 #19284546 未加载
评论 #19291728 未加载
jedimastertabout 6 years ago
Slightly to the side of the topic, but this quote here:<p>&gt;Yep, Bob uses i++ instead of ++i everywhere. Meh, what’s the difference.<p>I know what the difference is, but if you&#x27;re just using it on its own line or in a for loop, why would you use `++i` instead of `i++`?
评论 #19292748 未加载
评论 #19292163 未加载
评论 #19292431 未加载
评论 #19292124 未加载
neokantianabout 6 years ago
As soon as you default to a particular policy of how to allocate, and most importantly free, memory on the heap, you have committed yourself. Low level means: no commitment in that realm, aka, do what you please. The fact that you can possibly overrule that default, does not make much of a difference, because almost any language allows this.<p>C does not even have a standard (dynamically-sized) list concept built in, because that would amount to committing oneself to a default heap allocation&#x2F;deallocation policy. All you can get is a contiguous range of bytes with some vague, default interpretation as to what it is supposed to be, through the use of malloc&#x2F;free (possibly hacking it through realloc). That is why C is considered low level.<p>Still, in a true low-level solution, you would use the sbrk system call directly. So, in a sense, C may already &quot;add too much value&quot; to be considered truly low level.
评论 #19293195 未加载
评论 #19293204 未加载
mattnewportabout 6 years ago
Why was the conditional expression in the C++ code converted to an if statement in the C# code? C# has conditional expressions.
评论 #19291705 未加载
评论 #19291686 未加载
manigandhamabout 6 years ago
It&#x27;s subjective but recent language and runtime updates have made massive updates in performance and flexibility. There are projects like Unity, RavenDB document store, FASTER KV store, Trill analytics, ML.NET and many more that show that C# is incredibly capable of competing at low-level&#x2F;high-performance scenarios.
walkingolofabout 6 years ago
I would say no, but its all about lingo, low level languages, or system languages, can be used to bootstrap a computer.
samfisher83about 6 years ago
Can&#x27;t you just do pinvoke. It is easy enough to do. Just design a good interface in the c side to pass the data.
firethiefabout 6 years ago
Are trees tall?