Tag Archives: #C

CoD – Code of the Day – 1447441471

#include <stdio.h>

enum {WARNING, ERROR, INFO, SUCCESS};

char const *msg(int type);

int main (int argc, char **argv)
{

puts(msg(INFO));

puts(msg(0));
return 0;
}

char const *msg(int type)
{

switch (type)
{
case WARNING:
return “Warning message!”;
case ERROR:
return “Error message!”;
case INFO:
return “Info message!”;
case SUCCESS:
return “Success message!”;

}

return NULL;
}

The conjugate function for clang 3.4.1 on FreeBSD fails?

Dealing with the conjugate of complex numbers brought me some linker failures for clang 3.4.1 on FreeBSD 11 CURRENT amd64:

vanja@current:/tmp % cat konjugat.c
#include <complex.h>
#include <stdio.h>

int main(void)
{
double complex kpx = 1.0 + 3.0*I;
double complex konjugat = conj(kpx);
printf(“Kompleksni broj je %.2f%+.2fi\n”, creal(kpx), cimag(kpx));
printf(“Konjugat od kpx je %.2f%+.2fi\n”, creal(konjugat) ,cimag(konjugat));
return 0;
}

Continue reading