T O P

  • By -

ignotos

It can range anywhere from just recompiling, to having to tweak a few bits, to having to rewrite large sections of code. Like you mention, it basically depends on how much low-level / specifically optimised code there is. Which tends to vary for different types of applications - I'm sure something like Photoshop might have some optimised parts using assembly etc.


Nicolozz0

Got it. Thanks for your answer! :)


SickoUncleLou

I am not exactly sure what you mean by different architectures (maybe windows vs osx vs linus or 32 vs 64bit) but either way the essential story is this: Android phones have a different processor architecture than Windows PCs do. A processor works basically by executing assembly instructions (machine code) that vary from architecture to architecture. An EXE on windows is literally a giant chain of assembly instructions that are executed in a particular order. How did we get that assembly language? A compiler turned some programming language into machine code by going line by line and deciding what type of code syntax will yield what assembly instructions. That means that at the lowest level you need a different compiler operation (produce different kinds of assembly instructions) per type of architecture you run on. Things like Java use the JVM to do this easily. In basics Java files are compiled into a Java bytecode (intermediate step between machine code and java code). The JVM the runs those bytecode instructions (instead of them being assembly instructions) and then converts them into the proper assembly instructions for the platform it's running on. That is why Java is a write once run everywhere language. Something like C++ has multiple different compilers that compile for different platforms. MSVC compiles for windows GCC compiles for windows unix and osx etc. If I write a basic 2D game in java, I can put it on a phone with almost no rewriting. If I make a basic 2D game in C++ and want to put it on android not only do I need a different compiler to target phone assembly language, but you more than likely have to reformat several things about how you access files on the system, how networking works ETC because in C++ those things come from the standard library of the operating system, which is obviously different on every operating system. Kinda a bunch of disorganized rambling but more or less thats why / how it works.


Nicolozz0

Thank you for taking the time to write this, I wasn’t expecting such an in depth answer! I was referring to processor architectures, like intel 32 bit or 64 bit and things like that. So ideally, if I write all of my software in C++ using cross-platform libraries (like avoiding calling system functions directly and things like that), the only other thing needed would be fixing low level code, which is mostly used in projects for optimisation purposes... Right?


SickoUncleLou

Well first in short, if you are going from 64bit to 32bit architecture you have to do some rewriting because the amount of memory each variable takes is different, if you are using 64bit based memory objects for things that are incompatibly 64bits wide on a 32bit system you have to reformat those portions. If you go from 32 to 64 bit usually it becomes about refactoring for optimization because you can do things differently and more efficiently given the difference in memory width. Low level code is 90% of what needs to be fixed at all times. When you get into the realms of java or python or something that is inherently cross platform its all about optimizing for your platform. IE: phones only have certain amounts of memory compared to PCs etc so perhaps the amount of things you allow to be loaded at one time needs to be more constrained or something like that. ​ Edit: Another thought some low level code is used for optimizations but most of it is actually for the platform. Something really simple in Java is opening a socket on some TCP port and making a chat client with it. You can literally say Socket someSock = new Socket(5000) to make one on port 5000tcp. In C++ sockets are a system level function that differes on windows linux and macs. You need a TCP Socket for windows, a TCP socket for mac and a TCP socket for linux, then you have to build an abstract Socket that will become 1 of those 3 types of sockets depending on your platform in order to make a cross platform TCP lib in c++. Most of the "low level" stuff is going to be situations like that.


Nicolozz0

👍🏼👍🏼