Jump to content

Not able to use register in C.

Gat Pelsinger

I came upon this register keyword in C and wanted to see how fast it is comparing to standard memory. Code- 

 

#include <stdio.h>
#include <time.h>
#include <limits.h>

int main() {
    register unsigned long long x = 0ULL;
    clock_t start_time = clock();

    while (x < ULONG_LONG_MAX) {
        x++;
    }

    clock_t end_time = clock();

    printf("%llu\n", x);
    
    double elapsed_time = ((double)(end_time - start_time)) / CLOCKS_PER_SEC;
    printf("%lf seconds\n", elapsed_time);

    return 0;
}

 

But the problem is that I can't compile it without the optimization flags (o2 and o3). But this code compiles fine without any optimization flags, likely ignoring the register keyword. I use GCC-Mingw-w64 compiler. I get a LOT of errors when compiling with optimizations. If you want to read them-

C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.text+0x3d0): multiple definition of `WinMainCRTStartup'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x3d0): first defined here
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.text+0x3f0): multiple definition of `mainCRTStartup'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x3f0): first defined here
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.text+0x410): multiple definition of `atexit'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x410): first defined here
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:cygming-crtbeg:(.text+0x430): multiple definition of `__gcc_register_frame'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/crtbegin.o:cygming-crtbeg:(.text+0x0): first defined here
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:cygming-crtbeg:(.text+0x440): multiple definition of `__gcc_deregister_frame'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/crtbegin.o:cygming-crtbeg:(.text+0x10): first defined here
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:main.c:(.text+0x4a4): multiple definition of `main'; C:\Users\ANISH_~1\AppData\Local\Temp\cciyTXdh.o:main.c:(.text+0x54): first defined here
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.rdata+0x7b0): multiple definition of `.refptr.__mingw_initltsdrot_force'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__mingw_initltsdrot_force[.refptr.__mingw_initltsdrot_force]+0x0): first defined here
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.rdata+0x800): multiple definition of `.refptr.__native_startup_state'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__native_startup_state[.refptr.__native_startup_state]+0x0): first defined here
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.bss+0x0): multiple definition of `__mingw_module_is_dll'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.bss+0x0): first defined here
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.rdata+0x750): multiple definition of `.refptr.__imp___initenv'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__imp___initenv[.refptr.__imp___initenv]+0x0): first defined here
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.rdata+0x8a0): multiple definition of `.refptr._matherr'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr._matherr[.refptr._matherr]+0x0): first defined here     
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.rdata+0x870): multiple definition of `.refptr._dowildcard'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr._dowildcard[.refptr._dowildcard]+0x0): first defined 
here
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.rdata+0x7a0): multiple definition of `.refptr.__mingw_app_type'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__mingw_app_type[.refptr.__mingw_app_type]+0x0): first defined here
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.rdata+0x7e0): multiple definition of `.refptr.__mingw_oldexcpt_handler'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__mingw_oldexcpt_handler[.refptr.__mingw_oldexcpt_handler]+0x0): first defined here
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.rdata+0x840): multiple definition of `.refptr.__xi_a'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__xi_a[.refptr.__xi_a]+0x0): first defined here
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.rdata+0x8b0): multiple definition of `.refptr._newmode'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr._newmode[.refptr._newmode]+0x0): first defined here     
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.rdata+0x7d0): multiple definition of `.refptr.__mingw_initltssuo_force'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__mingw_initltssuo_force[.refptr.__mingw_initltssuo_force]+0x0): first defined here
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.rdata+0x7f0): multiple definition of `.refptr.__native_startup_lock'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__native_startup_lock[.refptr.__native_startup_lock]+0x0): first defined here
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.rdata+0x730): multiple definition of `.refptr.__dyn_tls_init_callback'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__dyn_tls_init_callback[.refptr.__dyn_tls_init_callback]+0x0): first defined here
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.rdata+0x7c0): multiple definition of `.refptr.__mingw_initltsdyn_force'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__mingw_initltsdyn_force[.refptr.__mingw_initltsdyn_force]+0x0): first defined here
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.rdata+0x890): multiple definition of `.refptr._gnu_exception_handler'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr._gnu_exception_handler[.refptr._gnu_exception_handler]+0x0): first defined here
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.CRT+0x20): multiple definition of `__mingw_pcinit'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.CRT$XIAA+0x0): first defined here
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.rdata+0x860): multiple definition of `.refptr._commode'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr._commode[.refptr._commode]+0x0): first defined here     
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.CRT+0x8): multiple definition of `__mingw_pcppinit'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.CRT$XCAA+0x0): first defined here
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.rdata+0x740): multiple definition of `.refptr.__image_base__'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__image_base__[.refptr.__image_base__]+0x0): first defined here
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.rdata+0x880): multiple definition of `.refptr._fmode'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr._fmode[.refptr._fmode]+0x0): first defined here
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.rdata+0x820): multiple definition of `.refptr.__xc_a'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__xc_a[.refptr.__xc_a]+0x0): first defined here
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.rdata+0x850): multiple definition of `.refptr.__xi_z'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__xi_z[.refptr.__xi_z]+0x0): first defined here
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.rdata+0x6f0): multiple definition of `.refptr._MINGW_INSTALL_DEBUG_MATHERR'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr._MINGW_INSTALL_DEBUG_MATHERR[.refptr._MINGW_INSTALL_DEBUG_MATHERR]+0x0): first defined here
C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.exe:crtexe.c:(.rdata+0x830): multiple definition of `.refptr.__xc_z'; C:/Users/USER/Downloads/x86_64-13.2.0-release-win32-seh-msvcrt-rt_v11-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__xc_z[.refptr.__xc_z]+0x0): first defined here
collect2.exe: error: ld returned 1 exit status

Microsoft owns my soul.

 

Also, Dell is evil, but HP kinda nice.

Link to comment
Share on other sites

Link to post
Share on other sites

Update - I was using wrong compiler flags. The program compiles now with optimizations.

Microsoft owns my soul.

 

Also, Dell is evil, but HP kinda nice.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×