Newbie question: Can I use both C and C++ ar the same time?
-
- Posts: 11
- Joined: Mon Aug 08, 2016 7:56 am
Newbie question: Can I use both C and C++ ar the same time?
Hi, I'm pretty new to the os development world and I was wondering if I could mix c and c++ for the developmento of my kernel, so I can use object oriented programming in the filesystem by example.
If it can be done, would you recommend doing it or should I just stick with C programming?
If it can be done, would you recommend doing it or should I just stick with C programming?
Re: Newbie question: Can I use both C and C++ ar the same ti
Yes, you can mix c and c++. Why not do it all in C++?
If a trainstation is where trains stop, what is a workstation ?
Re: Newbie question: Can I use both C and C++ ar the same ti
It is possible, I don't see a reason why not.
I would suggest you to stick with the language you know better.
C++ is good because it has classes and different types of variable access levels. In my opinion C is better and more used.
I would suggest you to stick with the language you know better.
C++ is good because it has classes and different types of variable access levels. In my opinion C is better and more used.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
Re: Newbie question: Can I use both C and C++ ar the same ti
To fully use C++ features you have to code alot of stuff first (like memory management, paging, etc) so you can use the "new" command for example.
AFAIK C++ needs a runtime for all its features which you have to offer by yourself (compiler shouldnt add it because it is ofc OS dependent)
AFAIK C++ needs a runtime for all its features which you have to offer by yourself (compiler shouldnt add it because it is ofc OS dependent)
-
- Member
- Posts: 1146
- Joined: Sat Mar 01, 2014 2:59 pm
Re: Newbie question: Can I use both C and C++ ar the same ti
Yes, that is true.Ch4ozz wrote:To fully use C++ features you have to code alot of stuff first (like memory management, paging, etc) so you can use the "new" command for example.
AFAIK C++ needs a runtime for all its features which you have to offer by yourself (compiler shouldnt add it because it is ofc OS dependent)
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
-
- Posts: 11
- Joined: Mon Aug 08, 2016 7:56 am
Re: Newbie question: Can I use both C and C++ ar the same ti
Another question, if i mix c and c++ code, do i have to use the extern "c" keyword to call c++ code from c?
Re: Newbie question: Can I use both C and C++ ar the same ti
Yes, C++ symbol names are mangled and cannot be used in C unless you mark your declarations with 'extern "C"'.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
- Alan Kay
Re: Newbie question: Can I use both C and C++ ar the same ti
That also means that you cannot use classes or namespaces(not really sure of this one) from C code, so you have to supply a C interface for classes.Roman wrote:Yes, C++ symbol names are mangled and cannot be used in C unless you mark your declarations with 'extern "C"'.
If some of you people keep insisting on having backwards compatibitity with the stone age, we'll have stone tools forever.
My Hobby OS: https://github.com/heatd/Onyx
My Hobby OS: https://github.com/heatd/Onyx
Re: Newbie question: Can I use both C and C++ ar the same ti
Yep, namespaces are done through mangling and therefore cannot be used in C. Classes can be imported through a layer consisting of wrapper global functions and opaque types.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
- Alan Kay
-
- Posts: 11
- Joined: Mon Aug 08, 2016 7:56 am
Re: Newbie question: Can I use both C and C++ ar the same ti
So I'm trying to use both C and C++ following the meaty skeleton tutorial, but when i use i686-elf-g++ as a linker in replacement of i686-elf-gcc so i can use c++ code i get this error:
It seems like a library is missing but i didn't find any other references to lk in the source
Code: Select all
i686-elf-g++ -T arch/i386/linker.ld -o XeonOS.kernel -O2 -g -ffreestanding -fbuiltin -Wall -Wextra -Werror arch/i386/crti.o /opt/cross/lib/gcc/i686-elf/5.4.0/crtbegin.o arch/i386/boot.o arch/i386/portio.o arch/i386/tty.o kernel/kernel.o /opt/cross/lib/gcc/i686-elf/5.4.0/crtend.o arch/i386/crtn.o -nostdlib -lk -lgcc
/opt/cross/lib/gcc/i686-elf/5.4.0/../../../../i686-elf/bin/ld: cannot find -lk
Re: Newbie question: Can I use both C and C++ ar the same ti
You have to set your library paths to the sysroot folder's. "lk" is the C library for the kernel, only with freestanding stuff. It's in sysroot/usr/lib/libk.a. I think you need to do something like "--sysroot ../sysroot/".DevilGladiator wrote:So I'm trying to use both C and C++ following the meaty skeleton tutorial, but when i use i686-elf-g++ as a linker in replacement of i686-elf-gcc so i can use c++ code i get this error:It seems like a library is missing but i didn't find any other references to lk in the sourceCode: Select all
i686-elf-g++ -T arch/i386/linker.ld -o XeonOS.kernel -O2 -g -ffreestanding -fbuiltin -Wall -Wextra -Werror arch/i386/crti.o /opt/cross/lib/gcc/i686-elf/5.4.0/crtbegin.o arch/i386/boot.o arch/i386/portio.o arch/i386/tty.o kernel/kernel.o /opt/cross/lib/gcc/i686-elf/5.4.0/crtend.o arch/i386/crtn.o -nostdlib -lk -lgcc /opt/cross/lib/gcc/i686-elf/5.4.0/../../../../i686-elf/bin/ld: cannot find -lk
If some of you people keep insisting on having backwards compatibitity with the stone age, we'll have stone tools forever.
My Hobby OS: https://github.com/heatd/Onyx
My Hobby OS: https://github.com/heatd/Onyx