Jump to content

C++ proposition


Jief_Machak
 Share

823 posts in this topic

Recommended Posts

4 hours ago, Jief_Machak said:

I'm on it.

First : which Version.h is the right one? Some files includes the one in the main dir and main.cpp include the one in rEFIt_UEFI.

It depends on build script. Let us suppose the good version is in root folder and correct all around this.

Link to comment
Share on other sites

6 hours ago, Jief_Machak said:

Now, Platform.h is a meta-header that includes basic need for all modules. It's supposed to contains only includes.

DO NOT define anything in there. I know it seems handy because it's instantaneously shared with all, but please don't. If it make sense to share something with all modules (macro, extern var or function), define it in the module it belongs to and create an include in Platform.h.

 

The point is to have modules that makes sense. A module is a bit like a C++ object. Everything is defined in the couple .h .cpp, then other modules include the header and start using it.

 

Everyone's ok with that ?

oops, forgot to update refit. Wait a sec before pulling.

It is good but the separate project "Clover.app" want to see SETTINGS_DATA and so #include "Platform.h".

Now it should include Settings.h?

Link to comment
Share on other sites

I have the memory of a post saying that Clover.app has now it's own copy SETTINGS_DATA.

It would be better if it's shared, of course. We can make a SettingsDataShared.h to share just what's needed and so avoid compilation problem.

For sure Clover.app shouldn't include Platform.h (but I understand why it did).

Link to comment
Share on other sites

Ok, so there is a problem when printing a unsigned value (%u, %x or %X) with a var type small then the formet : ie %X and UINT8. Because the uint8 is promoted to a bigger type, that's why we got a lot of 'F' before.

 

So we have to use the right specifier. One h for short, 2 hh for char and uint8.

 

The thing is that there is no warning if you use a smaller var than the format specifier when it's a 8 or 16 bits values. But there is a warning if you use %hhx with a 16 bits value.

 

Story short : when unsure of the type, start with hh and let the compiler tell you what

s right.

  • Thanks 1
Link to comment
Share on other sites

Even though long and long long are the same size, they are not the same type. It's annoying, I know.

So if INTN is defined as long long, we need the double l in %lld.

It's something builtin the compiler. It can be changed. I did it with GCC for Arduino. But the GCC source has to be patch and recompile...

Link to comment
Share on other sites

We may change ProcessorBind.h definitions

  /// 8-byte unsigned value

  ///

  typedef unsigned long long  UINT64;

  ///

  /// 8-byte signed value

  ///

  typedef long long           INT64;

  ///

 

 

 

to be

/// 8-byte unsigned value

  ///

  typedef unsigned long   UINT64;

  ///

  /// 8-byte signed value

  ///

  typedef long            INT64;

  ///

 

Why not?

Link to comment
Share on other sites

Entirely possible. But only do that if not Microsoft. long is 32 bits if compiled by VS. Which probably won't match to what EFI would expect.

If you'd like to change INT64, probably best to change UINT64 too.

 

Oh, but there is a problem if you do that : INT64 would %ld on CLANG/GCC and %lld on Microsoft. So I think we can't do that.

Link to comment
Share on other sites

I did quick test

    DBG("void=%ld int=%ld long=%ld longlong=%ld enum=%ld\n",

        sizeof(void), sizeof(int), sizeof(long int), sizeof(long long), sizeof(EFI_ALLOCATE_TYPE));

The result is

11:305  0:000  void=1 int=4 long=8 longlong=8 enum=4

Expected?

11 minutes ago, Jief_Machak said:

Entirely possible. But only do that if not Microsoft. long is 32 bits if compiled by VS. Which probably won't match to what EFI would expect.

If you'd like to change INT64, probably best to change UINT64 too.

 

Oh, but there is a problem if you do that : INT64 would %ld on CLANG/GCC and %lld on Microsoft. So I think we can't do that.

But %lld is under your control. You may just change it interpretation for the MSC case.

My displeasure is just text editing in Xcode as I shown in the screen above. These warnings are very annoying.

Link to comment
Share on other sites

Unfortunately no, the printf-like format checking is totally builtin compilers.

Yes, but in XCode, just click fix and they're gone.

Moreover : you have to click fix. It's a mistake to use %ld with long long and vice-versa.

 

Clover is compiling with 0 warnings on my computer. Isn't the same on yours ?

3 minutes ago, Slice said:

1:305  0:000  void=1 int=4 long=8 longlong=8 enum=4

Yes, expected.

and void=1 int=4 long=4 longlong=8 enum=4 for microsoft compilers.

Link to comment
Share on other sites

Our build_rules set -Werror so Clover must be compiled without warning. But XCode is annoying.

Button "fix" will change %lld to %ld which leads to error in batch compilation.

Why XCode thinks that INTN is long?

Снимок экрана 2020-04-19 в 20.17.20.png

It doesn't see headers?

Link to comment
Share on other sites

??? Change %lld to %ld ??? Very strange. Mine does the opposite.

 

Can you try with my CloverX64 project ? I'm pretty sure XCode indexer is picking up the wrong ProcessorBind.h and thinks that int64 are long. But they are long long ! (line 189 in X64/ProcessorBind.h)

 

I wouldn't have spent so much time doing that if it were to have warnings.

Link to comment
Share on other sites

CloverX64 project is not analysed by Xcode because headers absent. How can it knows what is INTN? The definition is out of the project.

24 minutes ago, Jief_Machak said:

It sees header,  but there is 9 different ProcessorBind.h in EDK. So maybe Xcode get confused.

 

Try with CloverX64 to confirm that you don't have an xcode problem. There should be no warnings at all.

Is that right ?

I may exclude other ProcessorBind files from the project.

Link to comment
Share on other sites

Just now, Slice said:

CloverX64 project is not analysed by Xcode because headers absent. How can it knows what is INTN? The definition is out of the project.

Not sure what that means. I didn't put the header in the project, right, but Xcode still finds them. Try do jump definition and you'll see it works (at least here it works). If I do jump definition on INT64, I end up in the correct ProcessorBind.h.

If I put a wrong printf format and I get the right warning..

Well, can you confirm it works.

Link to comment
Share on other sites

44 minutes ago, Jief_Machak said:

 

Yes, expected.

and void=1 int=4 long=4 longlong=8 enum=4 for microsoft compilers.

Not expected. Xcode8 compilation stopped

/Users/sergey/src/Clover/rEFIt_UEFI/refit/main.cpp:2153:9: error: invalid application of 'sizeof' to an incomplete type 'void'
        sizeof(void), sizeof(int), sizeof(long int), sizeof(long long), sizeof(EFI_ALLOCATE_TYPE));
        ^     ~~~~~~

 

Link to comment
Share on other sites

4 minutes ago, Jief_Machak said:

Not sure what that means. I didn't put the header in the project, right, but Xcode still finds them. Try do jump definition and you'll see it works (at least here it works). If I do jump definition on INT64, I end up in the correct ProcessorBind.h.

If I put a wrong printf format and I get the right warning..

Well, can you confirm it works.

No. I clicked Jump to definition on INTN and see

Снимок экрана 2020-04-19 в 20.56.58.png

This is the file MdePkg/Include/Ebc/ProcessorBind.h which is wrong.

4 minutes ago, Jief_Machak said:

You're not supposed to take "sizeof(void)".

 

Which Xcode Scheme do you use when compiling with Clover.xcworkspace ?

 

Default one

Снимок экрана 2020-04-19 в 21.01.00.png

Link to comment
Share on other sites

 Share

×
×
  • Create New...