C implementation