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
Nalin
Sep 29, 2007

Hair Elf
I'm having some issues compiling a unicode string class I wrote in GCC 4.5. It used to work fine, but I recently re-programmed the iterator to work in STL algorithms and everything broke horribly. It works just fine in Visual Studio 2010, but it generates a lot of errors in GCC 4.5.

Here is a zip file containing the class (irrUString.h), an extremely simple test program, and a couple headers required for irrUString.h to compile (it was developed to be integrated with the Irrlicht engine, so a couple Irrlicht-specific headers are required.)
http://irrlicht.suckerfreegames.com/test/ustring.zip

Just compile it like this:
g++ main.cpp -std=c++0x

Can anyone tell me why it is failing to see the typedefs defined in std::iterator? Do I really have to throw in a typename everywhere I use a typedef'ed name in order to get this thing to work? If anyone could tell me what I am doing wrong, I would much appreciate it.

Adbot
ADBOT LOVES YOU

Nalin
Sep 29, 2007

Hair Elf
Thanks, that was exactly what I needed. I got everything working after reading that.

Nalin
Sep 29, 2007

Hair Elf

Thrawn200 posted:

code:
// function declarations (prototypes)
Player welcome(Player); // this function will welcome the player
In your prototype section, you have declared that you have a function named welcome that takes a Player structure and returns a Player structure. When you provide the implementation, you never give a name to the Player that you pass in.
code:
Player welcome(Player p) {  // Name it p.
That lets you access the passed Player in your code.
Next, in your main function, you try to call welcome. Except, you aren't passing a variable into the function. You are passing the name of the class.

Furthermore, your logic for your welcome function is wrong. The function assigns a name to the global variable player1. It then returns player1's name and sets player1's name to the returned value. That is redundant and there is no need to do that at all.

What you are PROBABLY trying to do is this:
code:
// Define our Player structure.
struct Player {
    string name;
    string choice;
    int points;
};

// welcome will return a string containing the player's name.
string welcome(); // this function will welcome the player

int main(int argc, char** argv) {
    // Create a player.
    Player player1 = {"PlayerOne", "rock", 0};

    // Set the player's name to whatever welcome() returns.
    player1.name = welcome();
}

string welcome() {
    string p1;
    cout << "Let's get started..." << endl;
    cout << "What is your name?" << endl;
    cin >> p1;

    // if the user enters null then assign PlayerOne as name
    if (p1 == "") {
        p1 = "Player1";
    }

    // Return the name we just got.
    return p1;
}

Nalin fucked around with this message at 05:27 on Feb 20, 2011

Nalin
Sep 29, 2007

Hair Elf
EDIT: Oh no, beaten!

There is no 'elseif' statement. However, you CAN do this:
code:
if (condition)
  ...
else if (condition)
  ...
else
  ...

Nalin
Sep 29, 2007

Hair Elf

icantfindaname posted:

Is there any easy way to concatenate a character to a string in C? Specifically, take a character out of another string, iterating through with a for loop. I tried strcat but apparently it needs to be a constant char for that to work. The program is supposed to check whether a string is a palindrome.

code:
for (i = StringLength (InputLine) - 1; i >= 0; i--) {
	if (!(StringEqual (CharToString(InputLine[i]), " "))) {
		//insert concat function here
	}
}
When dealing with string functions in C, you have to remember that your destination character array has to have been allocated with enough characters to do whatever it is you are trying to do. If your destination character array is too small, you will have to create a new array and copy your old string into it.

That said, all you are trying to do is check if a string is a palindrome? You shouldn't need to do any concatenation at all.
code:
// Create a pointer to the beginning...
const char* ptr_to_start = InputLine;

// ...and the end of the string.  Subtract 1 so we aren't pointing to the terminating NULL.
const char* ptr_to_end = InputLine + strlen(InputLine) - 1;

// We start our loop.
// Check if the two pointers are equal.  If this is a palindrome, they should be.
// Also, add a check for the middle of the string.
while ((*ptr_to_start == *ptr_to_end) && (ptr_to_end - ptr_to_start > 1))
{
  // Move both pointers towards the middle.
  ++ptr_to_start;
  --ptr_to_end;
}

// If both pointers reached the middle, and they are equal, we have a palindrome!
if ((*ptr_to_start == *ptr_to_end) && (ptr_to_end - ptr_to_start <= 1))
  // success!  Is a palindrome.
else
  // failure!  Is not a palindrome.

Nalin fucked around with this message at 20:34 on Feb 23, 2011

Nalin
Sep 29, 2007

Hair Elf

Standish posted:

Also Nalin, looks like you need a tweak: http://codepad.org/zgM8s6YW
Well, that's embarrassing. I edited my post with a fix.

Nalin
Sep 29, 2007

Hair Elf

Manic Mongoose posted:

thanks for the help so far. :)
You know, I started to write out a description of an algorithm you could use before I realized how difficult this is going to be for you.

Take this as an example pattern:
....?x?ts

Based on the rules you gave, the following will match it:
eeeexts
eeexts
eeets

Once you start dealing with optional characters, it gets so much more difficult to design. You will need to try to pattern match against every combination of optional characters in your pattern. That means, you have to run your pattern match using the following patterns:
....xts
...xts
....ts
...ts

Testing against a simple pattern without any optional characters is easy. Just use two loops, like so:
code:
int pattern_match(char *pattern, char *str)
{
  // Loop through every character in the string.
  for (int i = 0; i <= strlen(str) - strlen(pattern); ++i)
  {
    // Search our pattern against our position.
    for (int j = 0; j < strlen(pattern); ++j)
    {
      bool escaped = false;

      // Do a test for \
      if (pattern[j] == '\\')
      {
        // Increment our position in our pattern so we test against
        // the actual character.  Also, we want to specify that escaped is true
        // so we don't try to interpret the . as an "any character" mark.
        ++j;
        escaped = true;
      }

      // Do a test for . if the . was not escaped.
      if (pattern[j] == '.' && !escaped)
        continue;

      // Check if our current position in the pattern matches our string.
      // If it is not set, break out of the loop and continue iterating along our string.
      if (pattern[j] != str[i + j])
        ..
    }

    // If we reached the end of our pattern without aborting early,
    // then we have a matching pattern!
    if (j >= strlen(pattern))
      return 1;
  }

  // Failure!
  return 0;
}
Unfortunately, I'm not aware of an easy algorithm that can handle optional characters.

Nalin
Sep 29, 2007

Hair Elf

nielsm posted:

I think the easiest way might be to do a recursive algorithm.
Oh yeah, that would definitely work. If we find an optional character, we just recursively call our pattern_match function to match WITHOUT the character. This should take care of all cases.

EDIT: Working code.

Try to implement nielsm's solution first before messing with this:
http://pastebin.com/6wEgxkgJ

Nalin fucked around with this message at 09:04 on Feb 25, 2011

Nalin
Sep 29, 2007

Hair Elf

nielsm posted:

That's bad, you can't use it recursively that way.
If you do this, any number of characters can appear between each character in the pattern.

Oh yeah, and don't ever use strlen() in a loop condition! Remember that strlen() is O(n) on the length of the string! The best way to loop over a string (in C) is the walking pointer method.
No, the code works. Well, it works now. There were some errors with it because I never tested it, but I updated my post with a working solution. And yeah, I know about not using strlen(). I just picked it because I figured it would be easier for him to understand.

Manic Mongoose posted:

Yeah, I had originally meant for you to write code for the blanks. There were some problems with my code (I never tested it), but I fixed them and edited my post with a working version.

If anybody else wants to try to solve it a different way, it would be interesting to see how you do it.

Nalin
Sep 29, 2007

Hair Elf

nielsm posted:

Actually no it doesn't. I just tried building it and it has exactly the problem I described.

code:
> rgrep-nalin.exe "ii" < rgrep-test.txt
this file is fine.txt
the filename s.txt is too short
and reallylong.txt is too long
but super.txt is just right!
All of the lines in the file have at least two "i"s, but none of them have two "i"s in succession.
That's weird because I get:
code:
Testing pattern: ii
: Testing string: this file is fine.txt
:  - Failure
: Testing string: the filename s.txt is too short
:  - Failure
: Testing string: and reallylong.txt is too long
:  - Failure
: Testing string: but super.txt is just right!
:  - Failure
EDIT: My solution returns -1 on failure. Maybe that is the cause of the discrepancy?

Nalin fucked around with this message at 09:05 on Feb 25, 2011

Nalin
Sep 29, 2007

Hair Elf

pr0metheus posted:

What is a good build system for C/C++ projects? I have been using cmake and love it so far, but there is probably something better out there?
I personally use premake. You specify your project details using Lua and premake uses that to generate a project file for you. It is pretty easy to use, but it is somewhat simple, so if you need something more advanced, it may be best to look at Mustach's list.

Nalin
Sep 29, 2007

Hair Elf

Super Ninja Fish posted:

code:
struct node result = malloc(sizeof(struct node));
struct node result->first = NULL;
code:
 struct node *result = (struct node *) sizeof(struct node);
result->first = NULL;
You are making a lot of errors here. It may be best for you to throw up your entire file onto a pastebin so we can see what you are trying to do.

Nalin
Sep 29, 2007

Hair Elf

Knyteguy posted:

A few more small questions: does __int64 (signed long long) only work on 64-bit systems? Why does it throw an error when I use it on codepad? What's a better alternative?
It works in 32-bit systems, but __int64 is specific to Microsoft's VC++ compiler. I would bet codepad is using a different compiler like GCC. Just use long long; it is C99/C++11 and pretty much every single compiler has supported it for ages (even Microsoft's compiler supports it.)

Nalin
Sep 29, 2007

Hair Elf

That Turkey Story posted:

Yeah. The code I posted lets you write:

code:
10201_digits
and it'll give you a null-terminated array of char made up of the digits of 10201 at compile-time, though compilers don't support user-defined literals yet :p
GCC 4.7 claims to support them.

Nalin
Sep 29, 2007

Hair Elf

UnfurledSails posted:

XCode outputs this as:

++a is: 4 and a++ is: 4

but when I try using g++ to compile then run the exec the output is:

++a is: 5 and a++ is: 3

Why is this?
e; This doesn't answer your question at all. Oops.
e2; The C++ standard doesn't define a specific way for an implementation to evaluate an expression. It looks like XCode is evaluating it from the left to the right, while g++ is evaluating it from the right to the left. In fact, the compiler may choose to evaluate everything randomly for optimization purposes.

Nalin fucked around with this message at 05:57 on May 18, 2012

Nalin
Sep 29, 2007

Hair Elf
Does anybody know how C++20's iterator concepts work? I've been trying to find information on how to construct a custom iterator for C++20's concepts, but I just haven't been able to find anything online describing the changes.

Is it some new style of designing your iterator class, or is it just an enhancement on top of the current method of tagging your iterator_category and providing your standard difference_type, value_type, etc, properties? Or is it just too early to think about this because no STL implementation has bothered with it yet?

Nalin
Sep 29, 2007

Hair Elf
code:
struct A2
{
    int x;
    int y;
    int data[2];
};

struct A3
{
    int x;
    int y;
    int z;
    int data[3];
};

template <typename T>
concept isA3 =
requires (T& t) {
    { t.x };
    { t.y };
    { t.z };
};

template <typename T> requires isA2<T>
void doStuff(const T& t);

template <typename T> requires isA3<T>
void doStuff(const T& t);

How can I make an isA2 concept that wouldn't make the doStuff function ambiguous for A3? Because no matter how much I search on stuff like SFINAE and whatnot, nobody ever seems to have ever had the question, "How do I check for something NOT existing?"

Nalin fucked around with this message at 02:58 on Mar 12, 2021

Nalin
Sep 29, 2007

Hair Elf

Nalin posted:

How can I make an isA2 concept that wouldn't make the doStuff function ambiguous for A3? Because no matter how much I search on stuff like SFINAE and whatnot, nobody ever seems to have ever had the question, "How do I check for something NOT existing?"

Took me forever but I was finally able to solve it.

code:
template<typename T>
concept isA3 =
requires (T& t)
{
    { t.x };
    { t.y };
    { t.z };
};

template<typename T>
concept pack_2 = (sizeof T::data / sizeof(std::remove_all_extents_t<decltype(T::x)>)) == 2;

template<typename T>
concept isA2 =
requires (T& t)
{
    { t.x };
    { t.y };
    requires pack_2<T>;
};

Nalin
Sep 29, 2007

Hair Elf

Jabor posted:

What I don't totally understand (perhaps because something is lost in converting the real situation to a toy example) is why the situation even uses templates and concepts to begin with.

Basically, I am using Google mathfu, which does terrible things like this:

code:
template <typename T>
class vector<T, 2>
{
    union {
        T data[2];
        struct {
            T x;
            T y;
        };
    };
};
I wanted to make a generic conversion function that could convert a vector<int, 2> to a vector<float, 2>, and any other data type. I also wanted it to work on vector<T, 3> with the same name, but overloaded.

Google was very nice in providing a vector::FromType/ToType function which helpfully just memcpy's the whole data[] array, because that's a great way to frustrate people trying to debug why everything has exploded. Turns out you can't memcpy a float into an int and make it work.

Nalin
Sep 29, 2007

Hair Elf

ShoulderDaemon posted:

I mean, I'm assuming that these things are packed appropriately for this to work correctly, but working with the integer-indexed data seems a lot simpler than trying to deal with overloads and named members.

It's at this point where "typedef mathfu::Vector<float, 2> Vector2df;" enters the whole codebase and screws up everything.

Nalin
Sep 29, 2007

Hair Elf

ShoulderDaemon posted:

I think I must not be understanding the problem you're encountering, because it works okay for me.

You know, you are probably right. I could have sworn I tried it and got an error. Wouldn't it just be my luck to have mistaken the problem and spent way too much time messing around with stupid stuff.

Nalin
Sep 29, 2007

Hair Elf

Nalin posted:

You know, you are probably right. I could have sworn I tried it and got an error. Wouldn't it just be my luck to have mistaken the problem and spent way too much time messing around with stupid stuff.

It's the next day and I'm refreshed now. I know why I didn't see that method of doing it. I was completely focused on doing:
auto vec = convert<Vector2di>(floatvec);

It is definitely a lot more simple to do:
auto vec = convert<int32_t>(floatvec);

Lime posted:

So your real question has already been answered but if for some reason in the future you really do need to check for a field not existing, you could do it like: (godbolt link)

Awesome, thanks! I eventually figured out a similar thing for a different problem I was having. Well, if anything, flailing around like this is definitely giving me a better understanding of things like SFINAE and concepts.

Nalin
Sep 29, 2007

Hair Elf

Beef posted:

With Concepts finally being in a released standard, are we seeing an uptick in the use of C++ template mixins?

I've never used mixins before, but at least in my hobby projects I've started to make use of concepts in general. I usually try to filter my template with a requires to reduce arcane compiler errors. Like, just a few days ago I took a template function that converts an enum to a number and threw a "requires std::integral<T>" on it. I've also taken to creating new concepts for templates that operate on class member variables and functions in order to make simpler error messages.

Nalin
Sep 29, 2007

Hair Elf

Vargatron posted:

If I malloc() a struct, do I have to enter in the struct size or will C figure that out on it's own based on the struct definition? I'm finishing up on my first semester of C programming and we're covering dynamic memory allocation.

You have to put in a size to be allocated. You generally do this with the "sizeof" operator.

code:
struct test {
  int a;
  float b;
};

int main() {
    struct test *t1, *t2;
    struct test *tarray;

    t1 = malloc(sizeof(struct test));  // sizeof(type)
    t2 = malloc(sizeof *t2);  // sizeof expression
    tarray = malloc(2 * sizeof(struct test));  // allocate two of them!

    free(t1);
    free(t2);
    free(tarray);

    return 0;
}

Nalin fucked around with this message at 20:20 on Apr 9, 2021

Nalin
Sep 29, 2007

Hair Elf

cheetah7071 posted:

Thanks, that was exactly what I was looking for, and the messiness involved is probably why I couldn't figure it out on my own

e: ::* is a spicy bit of syntax

You could just get into a habit of using std::function. It is slightly less messy!

C++ code:
// Shamelessly stolen a bit from cppreference.com
struct Foo {
    Foo(int num) : num_(num) {}
    void print_add(int i) const { std::cout << num_+i << '\n'; }
    int num_;
};

std::function<void(const Foo&, int)> foo_member_function = &Foo::print_add;
std::function<int(Foo const&)> foo_member_variable = &Foo::num_;

Nalin
Sep 29, 2007

Hair Elf
I've been smacking my head against C++20 modules for a while now and I just haven't been able to get my code to compile. Is anybody able to explain to me why this tiny solution doesn't compile in Visual Studio 2022? If I can find out why it is failing, I would be one step closer to getting my project to compile.

I get the following error:
C7621: module partition 'Part' for module unit 'File' was not found.

The project:
https://drive.google.com/file/d/1-9Rotd3c2qSmr1esoYs-1YTQmCYL1oMk/view?usp=sharing

Nalin
Sep 29, 2007

Hair Elf
Well, I think I've figured it out. Visual Studio 2022 17.0.4 cannot have a module implementation unit of a partition. I'm not sure if this is a limitation of modules or a bug with Visual Studio, but I can work around it by either not using partitions or only using partitions without an implementation unit.

Nalin
Sep 29, 2007

Hair Elf
C++20 introduces consteval, which can force a function to be evaluated at compile-time.

code:
template <uint8_t N>
consteval auto vecw_slli_lookup(VecW vv)
{
    static_assert(N < 8, "vecw_slli_lookup may only be used with N < 8.");
    return _mm_slli_epi64(vv, N);
}
gcc supports it well, but clang does not (partial support in clang 14). And iirc Apple clang is behind normal clang.

EDIT: Some searching shows this C++17 based solution:

code:
template <auto V>
struct constant {
    constexpr static decltype(V) value = V;
};

template <uint8_t N>
constexpr auto vecw_slli_lookup(VecW vv)
{
    static_assert(N < 8, "vecw_slli_lookup may only be used with N < 8.");
    return _mm_slli_epi64(vv, N);
}

int main()
{
    auto result = constant<vecw_slli_lookup<5>(0)>::value;
    return 0;
}

Nalin fucked around with this message at 07:04 on Jan 15, 2022

Nalin
Sep 29, 2007

Hair Elf

drilldo squirt posted:

So I put an entire text file of numbers into a string and want to take those numbers out of the string and put it into an array. Is their an easy way of doing that?

If C++ and space delimited and only includes numbers, you could just use an istream to read stuff in. Should reduce supporting code.

C++ code:
#include <cstdint>
#include <string>
#include <sstream>
#include <vector>
#include <iterator>

int main() {
    std::string my_string{ "123 456 789" };

    std::istringstream stream{ my_string };

    // You can move in C++20 to avoid a copy.
    // std::istringstream stream{ std::move(my_string) };

    // Construct numbers using an istream_iterator.
    // Need an empty one for the end because the constructor can't handle a default_sentinel.
    std::vector<int64_t> numbers{ std::istream_iterator<int64_t>{stream}, std::istream_iterator<int64_t>{} };

    return 0;
}
https://godbolt.org/z/oj5vGWafM

Nalin
Sep 29, 2007

Hair Elf

Xarn posted:

Yeah, I am stuck then. The entry point to this mess looks like MAGIC_MACRO( Derived::method ) and I don't think there is a way to split out "derived" in preprocessor.

Oh well, it isn't actually important, just interesting.

Would you be able to do something like this when creating your classes?

https://godbolt.org/z/4x4aW3Y68

EDIT: Actually, that would break Base.

Nalin fucked around with this message at 21:34 on Mar 8, 2022

Nalin
Sep 29, 2007

Hair Elf
Are you sure that C++20 changes anything with std::vector<bool>? I don't see any changes mentioned anywhere.

Nalin
Sep 29, 2007

Hair Elf

baby puzzle posted:

I want to do something with dates and times but I don't know where to start.

I want to create yearly "events" for which I can specify a month/day/time that they start. Then I need to be able to tell where those events are in relation to the current time. I might even want to do more advanced things like "the first day of spring."

Which library should I be using? Can std::chrono help me do this? I can't really understand anything in there. I'm using C++17.

I may just wind up manually entering timestamps for the events for the next 10 years or something. But if there's a library out there that can make this easy then I'd like to do things properly.

Honestly, std::chrono is not going to help you unless you move to C++20 as all of the important calendar functions you want weren't implemented until then. With C++17, all you can really do is grab time points from your system clock and calculate durations between two times.

The calendar functionality is what you need to create time points based on dates. It lets you construct time points based off month/day/year, the second Tuesday of a month, etc, and even has some basic functionality like figuring out what day of the week your time is on. However, it cannot do anything more advanced like finding out what day spring starts. But it could do everything else you need.

But again, C++20 required. And sorry, I don't know of any date library that would help you off the top of my head. And sadly cppreference.com doesn't list any either.

Nalin
Sep 29, 2007

Hair Elf
You could use std::bind if you don't want to use a lambda, but I think the general consensus the last time I looked into this is to just use a lambda.

BTW, std::bind would look like this:

code:
struct Foo {
    void bar1(int a) {}
    void bar2(int b) {}
};

using MyFunc = std::function<void(int)>;

void myBarFunc(MyFunc f)
{}

Foo foo;
MyFunc fun = std::bind(&Foo::bar2, &foo, std::placeholders::_1);
myBarFunc(fun);

Nalin
Sep 29, 2007

Hair Elf
I've been playing around with modules in one of my hobby projects. I've ICE'd the compiler on multiple versions so far and even logged an EDG (Intellisense) bug. Your first mistake you'll make is trying to import <stl>; You'll try over and over to make it work but eventually you'll just give up. And lol get hosed if you try to use boost.

If you want to try modules, it's probably best to just use MSVC 2022. It's probably the best so far out of all of them. AFAIK, cmake still hasn't figured out how they'll do modules yet.

Nalin
Sep 29, 2007

Hair Elf

cheetah7071 posted:

while I am still deeply curious how I managed to get a situation where the linker was complaining about being unable to find a file I wasn't trying to link to, I switched to vcpkg and everything works now so good riddance, I guess

Boost will use #pragma comment(lib, ...) when the build system is MSVC (or Borland!) This means that the boost headers that you use will auto-link the appropriate boost library. If your build system doesn't install the libs with the correct file name, or you don't pass in #defines to control the auto-linking, you'll have problems.

See also: https://www.boost.org/doc/libs/1_63_0/boost/config/auto_link.hpp

Nalin fucked around with this message at 22:28 on Nov 20, 2022

Nalin
Sep 29, 2007

Hair Elf
If you wanna have fun writing up compiler bug reports, just try to use C++20 modules in Visual Studio. I've ICE'ed the compiler a couple times already.

Nalin
Sep 29, 2007

Hair Elf
There are many C++ features that people hem and haw over and like to proclaim that nobody should use them. The person in question is just new to C++ and was concerned if this was one of those features that would make life difficult down the road.

I am of the opinion that using "if constexpr" is a LOT more easier than dealing with SFINAE stuff on templates and to go ahead and use it all you want.

Nalin
Sep 29, 2007

Hair Elf

AgentF posted:

Question: how come this code compiles and works fine with gcc but not msvc?


code:
std::inclusive_scan( input.cbegin(), input.cend(), output.begin(), std::ranges::max );
The error message is: " 'std::ranges::_Max_fn::_Max_fn(const std::ranges::_Max_fn &)': attempting to reference a deleted function". My only guess is that I'm creating an instance of the std::ranges::max struct and then it attempts to call the copy constructor when passing it into the STL function call? I'm not sure how to fix this problem without introducing the noise of a lambda. Neither passing a reference to max nor trying to std::move it work either.

https://godbolt.org/z/e541rovPn

This seems to work. What is weird is that inclusive scan says it takes a "FunctionObject" for "binary_op", of which a function pointer should be valid, but the example uses stuff from <functional>, which are all structs with an operator() override.

Using a struct with an operator() override seemed to have worked.

Nalin
Sep 29, 2007

Hair Elf
I would probably start on just the concept of memory. Get some graphing paper, tell them that every box is a byte, and start numbering them. Show how bytes, shorts, ints, longs, etc are stored by blocking out multiple boxes. Show how a simple struct is stored. Then explain that a pointer is just a 32/64 bit integer. Block out an integer in the boxes and write in a number that logically represents the id of a different block on the sheet. Maybe erase the number and change it to show how changing the pointer is changing the box it is pointing to. Then explain that the data type associated with the integer just tells the compiler how to interpret the data it sees at that point. Say that the pointer is a byte, then a short, then an int, and show how it reinterprets what it sees.

I think that as long as they can conceptually identify that a pointer is just a normal integer and the compiler interprets it in a special way, it would go a long way to helping them understand some of the most complicated parts of C.

Adbot
ADBOT LOVES YOU

Nalin
Sep 29, 2007

Hair Elf
Yeah, I'm not sure if you can rely on floating point math to be identical between Intel/AMD, or even within different CPU generations of the same company.

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