Translating C/C++ to V

Posted by yhuang
Public (Editable by Users)
// TODO: translating C to V will be available in V 0.3. C++ to V will be available later this year.
// V can translate your C/C++ code to human readable V code. Let's create a simple program test.cpp first:

#include <vector>
#include <string>
#include <iostream>

int main() {
	std::vector<std::string> s;
	s.push_back("V is ");
	std::cout << s.size() << std::endl;
	return 0;
// Run v translate test.cpp and V will generate test.v:
fn main {
	mut s := []
	s << 'V is '
	s << 'awesome'
// An online C/C++ to V translator is coming soon.
// When should you translate C code and when should you simply call C code from V?
// If you have well-written, well-tested C code, then of course you can always simply call this C code from V.

// Translating it to V gives you several advantages:
// - If you plan to develop that code base, you now have everything in one language, which is much safer and easier to develop in than C.
// - Cross-compilation becomes a lot easier. You don't have to worry about it at all.
// - No more build flags and include files either.