-3

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;
MSalters
  • 173,980
  • 10
  • 155
  • 350
Duxa
  • 966
  • 2
  • 14
  • 27

1 Answers1

5

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

bolov
  • 72,283
  • 15
  • 145
  • 224
  • This is C though, not C++. Same applies? – Duxa Oct 10 '18 at 07:24
  • 4
    @Duxa and just how are you using `iostream` in C ??? – bolov Oct 10 '18 at 07:24
  • @Duxa and yes, it applies to C as well. Except the header is `stdint.h` instead. – bolov Oct 10 '18 at 07:26
  • Yeah I am an idiot, I didnt realize I was looking at C++ documentation. was trying to include it to read a file. Need to find a C solution. Thank you. And I was aware of stdint.h but figured it would be including too much unneeded stuff so opted to use typedef instead. Good to know that this is illegal. – Duxa Oct 10 '18 at 07:28