include iostream breaks uint32_t definition (C)

411 Views Asked by At

Edit: Please disregard this question. I realized that I am an idiot and very nice and helpful people pointed out iostream is not a C but a C++ library.

I am encountering a very strange problem.

I have a fully working program (about 1000 lines). I need to

#include <iostream> 

When I do so typedef of uint32_t breaks.

It is defined as such

typedef unsigned __int32 uint32_t;

I am using Visual Studio 2017. And this is the error it gives

\vc\tools\msvc\14.15.26726\include\cstdlib(19): error C2061: syntax error: identifier 'noexcept'

and when I hover over now underlined uint32_t the following is said:

uint32_t variable "uint32_t" is not a type name

commenting just the line

#include <iostream>

the program compiles and runs as expected.

What gives?

Side question. The reason I am using uint32_t is to guarantee that my variable is 32 bit long as I am doing a lot of bit manipulation. Would using unsigned int instead be safe?

Here is a list of everything I am including:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <iostream>

typedef unsigned __int32 uint32_t;
1

There are 1 best solutions below

4
bolov On

Declaring uint32_t yourself is illegal afaik. Don't do that. C++ has a standard one. Use that. It's declared in cstdint.

https://en.cppreference.com/w/cpp/types/integer

If you are in C then the header you need to use is stdint.h instead:

https://en.cppreference.com/w/c/types/integer