Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
xgalaxy
Jan 27, 2004
i write code
It’s been awhile since I’ve used Visual Studio. Is there seriously no way to stop it from throwing IntelliSense errors on *.inl files?

xgalaxy fucked around with this message at 04:44 on Oct 12, 2019

Adbot
ADBOT LOVES YOU

Dren
Jan 5, 2001

Pillbug

peepsalot posted:

I got a cmake / toolchain question. I have a project that uses cmake and I want to have it build with all clang/llvm tools.

I found that I have to initialize cmake with:
CXX="clang++" LDFLAGS="-fuse-ld=lld" cmake .

I also found these instructions to verify the correct linker is used:


And when I run that on my binary, I see lld and clang being used, but also GCC?

I don't understand where that's still coming from. I do have some *dynamically* linked libraries, which I believe were built with GCC, but would dynamic libraries cause GCC to leave a comment in the binary?

Or is there possibly some other part of the toolchain I'm not setting correctly to make it 100% clang/llvm?

If you wanna see what your compile is really doing run cmake like usual then run
code:
VERBOSE=1 make
instead of just make. It will output every build command in detail so you’ll be able to see which compiler and linker are called.

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

I need to know how many bits a given unsigned integer fits into.

I have been told that c++20 will have something for this: http://eel.is/c++draft/bit.pow.two#itemdecl:4
But I'm limited to c++14 for this project.

I want this to be as portable as possible across compilers (gcc, clang, msvc) and architectures (x86 or arm, 32 or 64bit).

The simplest thing would be to loop through powers of two, shifting left each iteration and checking if (pow2 >= value), but I would like to use intrinsics / builtins wherever possible. I think I'll only need it on size_t so basically it needs to support either uint32_t or uint64_t afaik.

GCC (and clang i think) can use
pre:
__builtin_clz[l[l]]
from here then subtract that result from the total bits in the integral type, and MSVC has some per-architecture lzcnt intrinsics I guess.

So I'm wondering how hard would it be to write any equivalent template while limited to c++14.

The annoying thing is that these builtins have input types like unsigned int, unsigned long, unsigned long long rather than explicitly sized uint32_t etc.

So my problem is I don't really understand how to implement static checks well enough to write something that chooses the correct builtin or intrinsic based on the provided type. This all seems incredibly complicated for what should be a really simple operation. :(

Zopotantor
Feb 24, 2013

...und ist er drin dann lassen wir ihn niemals wieder raus...

peepsalot posted:

I need to know how many bits a given unsigned integer fits into.

I have been told that c++20 will have something for this: http://eel.is/c++draft/bit.pow.two#itemdecl:4
But I'm limited to c++14 for this project.

I want this to be as portable as possible across compilers (gcc, clang, msvc) and architectures (x86 or arm, 32 or 64bit).

The simplest thing would be to loop through powers of two, shifting left each iteration and checking if (pow2 >= value), but I would like to use intrinsics / builtins wherever possible. I think I'll only need it on size_t so basically it needs to support either uint32_t or uint64_t afaik.

GCC (and clang i think) can use
pre:
__builtin_clz[l[l]]
from here then subtract that result from the total bits in the integral type, and MSVC has some per-architecture lzcnt intrinsics I guess.

So I'm wondering how hard would it be to write any equivalent template while limited to c++14.

The annoying thing is that these builtins have input types like unsigned int, unsigned long, unsigned long long rather than explicitly sized uint32_t etc.

So my problem is I don't really understand how to implement static checks well enough to write something that chooses the correct builtin or intrinsic based on the provided type. This all seems incredibly complicated for what should be a really simple operation. :(

Bit Twiddling Hacks

Xerophyte
Mar 17, 2008

This space intentionally left blank

Note that the ceil(log2(x)) function for finding the minimum required bit count is still 32-bit specific. You'll need to make specific versions for other word sizes if you want to handle char, short, uint64_t, size_t, etc. This isn't that hard, but it's a step.

I guess you'd then do some basic enable_if<is_unsigned<T>::value && sizeof(T) == sizeof(uint32_t)>-ish SFINAE to resolve to the right version for unsigned types of whatever widths you care about and fail for signed or non-integral types. Not sure if there's a better way to accomplish that.

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
I want to get the current time. Not the time on the user's machine, but like the actual time. It seems I need to create an SNTP or NTP client. Is there a library that just does this? Because I can find a lot of snippets that feel dubious and many don't compile on Windows because I don't have sys/socket.h like this one: https://stackoverflow.com/questions/9326677/is-there-any-c-c-library-to-connect-with-a-remote-ntp-server

I'd rather there were a nice library instead of copy and pasting some random poo poo from stackoverflow.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Just grab the reference implementation (or an appropriate port) from ntp.org?

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
I don't think that is what I want. I looked at it and didn't really know what I was looking at.

Actually I might just use https://timezonedb.com

e: well that just opens another can of worms. What's a simple way to do an http request? I looked at libcurl and it looks like overkill. There are a few "header only" libraries but they don't build for whatever reason.

baby puzzle fucked around with this message at 17:07 on Nov 2, 2019

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

baby puzzle posted:

e: well that just opens another can of worms. What's a simple way to do an http request? I looked at libcurl and it looks like overkill. There are a few "header only" libraries but they don't build for whatever reason.
You can just use a socket, write "GET [path] HTTP/1.0\nHost: [hostname]\n\n" to it, and parse what comes back. If you don't mind assuming success you can just read blindly until you hit two newlines in a row, then everything after that is the content.

pseudorandom name
May 6, 2007

roomforthetuna posted:

You can just use a socket, write "GET [path] HTTP/1.0\nHost: [hostname]\n\n" to it, and parse what comes back. If you don't mind assuming success you can just read blindly until you hit two newlines in a row, then everything after that is the content.

Next you'll be suggesting they write their own TLS implementation from scratch.

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
I think I figured out what my compile issues were with using sockets. I had to use WIN32_LEAN_AND_MEAN, but then fix some spots where I needed that. So I think I should be able to use one of those header-only libraries now. e: yeah this one builds now so I should be good: https://github.com/yhirose/cpp-httplib

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

pseudorandom name posted:

Next you'll be suggesting they write their own TLS implementation from scratch.
If the complaint is that a library is too heavyweight, the lightest-weight way to do it seems like a reasonable suggestion.
What I was really suggesting is "just use the library".

Edit: Also note that the "header-only" option is only actually header-only with no SSL or compression support, otherwise it's hidden dependencies on other libraries being present.

roomforthetuna fucked around with this message at 17:50 on Nov 2, 2019

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
Well none of the small libraries that I tried worked and I have no idea why. Maybe I'll have to use libcurl? But I don't even know where to start with that.

I would like to know how to do this kind of thing because it seems generally useful.

Absurd Alhazred
Mar 27, 2010

by Athanatos
Once you figure out how to get UTC, you have to convert it to local time, which can be an adventure in itself.

pseudorandom name
May 6, 2007

baby puzzle posted:

Well none of the small libraries that I tried worked and I have no idea why. Maybe I'll have to use libcurl? But I don't even know where to start with that.

I would like to know how to do this kind of thing because it seems generally useful.

You ask the OS what time it is right now.

Dren
Jan 5, 2001

Pillbug
If you want to do a GET w/ SSL support and everything else, have a look at https://github.com/Microsoft/cpprestsdk

If the requirement is ntp why not set up ntp on the host itself?

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

Anyone know a good tool that's not Java based to help find duplicate or unused code across a C/C++ project?

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

peepsalot posted:

Anyone know a good tool that's not Java based to help find duplicate or unused code across a C/C++ project?

http://clang-analyzer.llvm.org/scan-build.html ?

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

While that looks like a useful static analysis tool, I'm not seeing any specific checker for it to find duplicated code, but maybe I'm missing something?

Turtlicious
Sep 17, 2012

by Jeffrey of YOSPOS
This is my programming homework, I've looked in the book and looked online.

Can anyone tell me why my program isn't A.) finding the smallest number in the arrays (It's always returning the number I put into it. and B) isn't adding the 2 arrays together. and C.) isn't finding the largest or smallest numbers in the later arrays.

https://docs.google.com/document/d/1z_m9hHmQ6EvDii0sBf8XWwvl1yS7uMhyRZIOpIsFfOw/edit?usp=sharing

ullerrm
Dec 31, 2012

Oh, the network slogan is true -- "watch FOX and be damned for all eternity!"

Turtlicious posted:

This is my programming homework, I've looked in the book and looked online.

Can anyone tell me why my program isn't A.) finding the smallest number in the arrays (It's always returning the number I put into it. and B) isn't adding the 2 arrays together. and C.) isn't finding the largest or smallest numbers in the later arrays.

https://docs.google.com/document/d/1z_m9hHmQ6EvDii0sBf8XWwvl1yS7uMhyRZIOpIsFfOw/edit?usp=sharing

Have you tried stepping through the code in a debugger and seeing what the values of R and C are in each loop?

In almost all of your loops, you forget to set C to 0 as the starting value.

Turtlicious
Sep 17, 2012

by Jeffrey of YOSPOS

ullerrm posted:

Have you tried stepping through the code in a debugger and seeing what the values of R and C are in each loop?

In almost all of your loops, you forget to set C to 0 as the starting value.

:doh: thank you so much.

Turtlicious fucked around with this message at 05:52 on Nov 10, 2019

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
You should always be building C/C++ code with a ton of warnings on (and actually paying attention to them). There are so many things about these languages that really just should not be allowed and which are only caught by warnings. It's far beyond "best practice"; anybody writing code in these languages without paying attention to warnings is just being foolish. That is true even for highly experienced programmers; as a novice, it will save you again and again and again.

If you are using GCC or Clang, the option you want is -Wall. That will make some somewhat pedantic complaints that you might find annoying, but trust me, just fix them anyway so that you get into the habit of treating warnings as serious.

Dren
Jan 5, 2001

Pillbug
-Wall -Werror

netcat
Apr 29, 2008

I tried this tool and got some nice python UnicodeDecode exceptions in the output data but I can't figure out where I should report bugs.

Foxfire_
Nov 8, 2010

-Wall is also, despite the name, only the warnings that gcc developers think should always be turned on, not everything. If you're using gcc you should look through the warnings documentation and choose a set that works for you

I myself am partial to: -Wall -Wextra -Wpedantic -Wcast-qual -Wdouble-promotion -Warray-bounds=2 -Wtrampolines -Wunsafe-loop-optimizations -Wconversion -Wparentheses -Wlogical-op

Foxfire_ fucked around with this message at 01:57 on Nov 11, 2019

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
-Wgive-me-all-the-warnings-you-have -Wno-thats-too-many

Turtlicious
Sep 17, 2012

by Jeffrey of YOSPOS
That sounds useful, sounds like I should switch off Eclipse.

Turtlicious
Sep 17, 2012

by Jeffrey of YOSPOS
Does GCC have an installer?

nielsm
Jun 1, 2009



If you use Eclipse for C++ development and you don't remember installing GCC or Clang yourself, then Eclipse installed it for you. It will be using one of those two for C++ compiler already.

Turtlicious
Sep 17, 2012

by Jeffrey of YOSPOS

Foxfire_ posted:

-Wall is also, despite the name, only the warnings that gcc developers think should always be turned on, not everything. If you're using gcc you should look through the warnings documentation and choose a set that works for you

I myself am partial to: -Wall -Wextra -Wpedantic -Wcast-qual -Wdouble-promotion -Warray-bounds=2 -Wtrampolines -Wunsafe-loop-optimizations -Wconversion -Wparentheses -Wlogical-op

I found this and set all the warnings on, but I can't add all the stuff you have on through Eclipse.

Qwertycoatl
Dec 31, 2008

Not an eclipse user but there should be space somewhere to pass in arbitrary flags, maybe in Miscellaneous?

feedmegin
Jul 30, 2008

Turtlicious posted:

Does GCC have an installer?

./configure && make && sudo make install :sun:

Turtlicious
Sep 17, 2012

by Jeffrey of YOSPOS
There we go, it was in miscellaneous.

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
I have this struct:

code:
struct MagicLine
{
	math::float2 m_Position;
};
That I was initializing like this parameter here:

code:
m_MagicLine.SetValue( { {  8.0f, 2.0f } } );
But then I needed to add a constructor:

code:
struct MagicLine
{
	math::float2 m_Position;
	MagicLine( int ) {}
};
And now the curly brackets don't work anymore. I get this error C2664: cannot convert argument 1 from 'initializer list' to 'T'

How can I get both the constructor and the curly-bracket initializer list to work?

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
You need to add a constructor that accepts a float2.

When you have no constructor, your struct is eligible for aggregate initialization, where the values in your initializer list are just copied into the fields of the struct. Once you add a constructor, that no longer applies, so the compiler needs to match up your initializer list against an appropriate constructor.

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
Ok, that's easier than I thought it was going to be. The curly bracket construction still works. Thanks.

General_Failure
Apr 17, 2005
I feel pretty dumb and need some help.

First of all, ARM32 architecture.
I have this:
code:
__global_reg(6) void *sb;
*sb is a pointer to the base of the assembly static workspace. I have the elements of the workspace converted to a C header via a perl script (not mine. it's a part of an OS build system).

So it's just converted to a big list of #defines.
eg/
code:
#define FOO_BaseAddr    (4)
#define BAR_BaseAddr    (32)
#define BAZ_BaseAddr    (33)
or whatever. It's a big list.

How in the fresh hell do I get C to let me safely (in regards to sb) do some pointer arithmetic to sb to access what I need? I'm fighting with the compiler over casting. It's very anal retentive. I'm returning to an old project and want to see if I can write some HAL code in C instead of assembly. Most of the hardware is straightforward, but some is an absolute mindfuck that must have been designed by a sadist. In that cas it'd be nice to be able to abstract myself a little.

e:
Modified rubber ducky debugging works again. Ie posting.
Here's a pointless test function that builds.
code:
uint32_t calcUARTBase(uint32_t busnum)
{
  uint32_t *uartbase;
  uartbase = (uint32_t*) sb;
  uartbase += (HALUART_Log + (busnum << 2));
  return *uartbase;
}

edit again. Before anyone says it I know it's fragile. It's just a throwaway with no actual purpose. But it will be easy to compare the result with the address in the static workspace.

General_Failure fucked around with this message at 06:11 on Dec 2, 2019

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Okay, so your magic global register contains a pointer to a structure with fields at the given offsets, which you want to read? The offsets in your example are all multiples of 4; are they supposed to be offsets in bytes or in 32-bit chunks?

Assuming they’re in bytes, you should declare sb as a char* and then do something like:

C++ code:
return ((uint32_t*) (sb + HALUART_Log))[busnum];

Adbot
ADBOT LOVES YOU

General_Failure
Apr 17, 2005

rjmccall posted:

Okay, so your magic global register contains a pointer to a structure with fields at the given offsets, which you want to read?
That sums it up. Yes. Most of those fields hold the logical addresses of various hardware. Some just hold values of things.
This little dance is needed when working with the HAL because it's below a decent chunk of the OS functionality.
The static workspace is a construct which the developer (me in this case) creates and uses to hold the sacred values which keep the OS' poo poo together.

quote:

The offsets in your example are all multiples of 4; are they supposed to be offsets in bytes or in 32-bit chunks?
The offsets are in bytes.
In the case of my toy example, IIRC there are five UARTS. I have the base addresses stored sequentially. Hence using the shift to get word offsets from HALUART_Log.
I could have a switch and reference each offset by name, but why? Anyway the UART was one of the very first things I did a couple of years ago or so in assembly and it works fine. I just chose it as an example because it's simple but representative.

quote:


Assuming they’re in bytes, you should declare sb as a char* and then do something like:

C++ code:
return ((uint32_t*) (sb + HALUART_Log))[busnum];
It builds fine. Testing is a bit harder right now. What's the size of the array element you used for busnum? I'm a little fuzzy on whether it is in 8 or 32 bit increments in your example.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply