Better HN
topnewbestaskshowjobs
Log inSign up

shortrounddev2

2,427 karma · joined Jun 15, 2023 (3y ago) · 1,641 submissions

Submissions

comment 3y ago · link · parent

If you're calling Win32 functions it's already not compatible with other OSes... If you want to use cross platform code with files, use the C or C++ standard library's file handling functions.

C++ also supports wstring, but its implementation is dependent on the platform for god knows what reason.

utf-16 is also supported in C11:

https://en.wikipedia.org/wiki/C11_(C_standard_revision)#Chan...

> Improved Unicode support based on the C Unicode Technical Report ISO/IEC TR 19769:2004 (char16_t and char32_t types for storing UTF-16/UTF-32 encoded data, including conversion functions in <uchar.h> and the corresponding u and U string literal prefixes, as well as the u8 prefix for UTF-8 encoded literals).

You can use uchar.h for converting instead of the Win32 functions.

Here's a helper I wrote to wrap these string types in std::string and std::wstring:

    bool mbStrToWideChar(string const& in, wstring& out)
    {
        bool status = true;
        i32 bufferSize = MultiByteToWideChar(
            CP_ACP, 0, in.c_str(), -1, nullptr, 0
        );

        WCHAR* buffer = new WCHAR[bufferSize];
        i32 conversionResult = MultiByteToWideChar(
            CP_ACP, 0,
            in.c_str(), -1,
            buffer, bufferSize
        );

        if (!conversionResult)
        {
            cerr << "Failed to convert ANSI string [" << in << "] to Wide string!" << endl;
            status = false;
            goto Delete;
        }

        out = wstring(buffer);

    Delete:
        if (buffer)
        {
            delete[] buffer;
        }
        return status;
    }
and

    bool wideStrToMbStr(wstring const& in, string& out)
    {
        // Get buffer size
        i32 bufferSize = WideCharToMultiByte(
            CP_UTF8, 0,
            in.c_str(), (i32)in.size(),
            nullptr, 0,
            nullptr, nullptr
        );

        // Set outstring to new buffer size
        out = string(bufferSize, '\0');

        //Convert
        i32 res = WideCharToMultiByte(
            CP_UTF8, 0,
            in.c_str(), (i32)in.size(),
            &out[0], (i32)out.size(),
            nullptr, nullptr
        );
        if (!res)
        {
            wcerr << L"Failed to convert Wide string [" << in << L"] to ANSI string!" << endl;
            return false;
        }
        return true;
    }

comment 3y ago · link · parent

> Alternatively you can set the process code page to UTF-8 and call the 'A' variant API directly, but only sometimes, and only with Windows 10 v1903+, and you might still have to change the system locale setting and reboot

There is no need to do this; you can just call the A variant by name. Wide char and ascii functions are distinguished with W or A at the end, such as CreateFileA or CreateFileW. CreateFile is a macro.

comment 3y ago · link · parent

Try working on your communication/interpersonal skills, man. You're not a good communicator because I had no idea what you were trying to say until this post. You also shouldn't get upset by discussions of shells on the internet. You probably should take some time away from the computer.

This statement:

> The PROGRAMS. Who wants to rewrite everything because you can no longer pipe or redirect?

Is almost unintelligible, aside from the fact that I guess it qualifies as a nearly-correct statement in English

comment 3y ago · link · parent

You can still pipe

comment 3y ago · link · parent

> Dumb pipes and smart ends are future proof

Shell scripts should not live long enough to require being future proof. If you need to rely long term on some code, write it in an actual programming language

comment 3y ago · link · parent

I think people want a kind of declarative way for the application to pick up their files and build them, often simultaneously

comment 3y ago · link · parent

there's also nushell and powershell, which i think are an evolution over the shells which only pipe streams of bytes to programs

comment 3y ago · link · parent

> without the wonky syntax

Idk about you but every shell syntax on a unix-like OS is wonky to me

comment 3y ago · link · parent

Also an easier way to search subdirectories without having to invoke the shell to enumerate those files. A runtime with filewatxhers for hotswap compiling of .o files at runtime. Basically all the stuff msbuild provides

comment 3y ago · link · parent

> What were Washington’s objectives in sabotaging the Minsk peace plan and cold-shouldering subsequent Russian proposals, in provoking Russia by crossing clearly demarcated red lines, in pressing for Ukraine’s membership in NATO

Oh cool just more bullshit from a bought and paid for Russian asset

comment 3y ago · link · parent

I agree. But as it stands, 40% of students end up failing to graduate on time, and of the 60% that do, I imagine a decent chunk of them will end up with more debt than increased lifetime salary will pay for.

I'd estimate (generously) that maybe 25% of the people who go to college these days should, and 75% should not

comment 3y ago · link · parent

It's not

comment 3y ago · link · parent

I don't see how, but more importantly I don't see who this harms

comment 3y ago · link · parent

Microsoft already has most of the market, but Apple has made some gains in recent years. Microsofts biggest threat is mobile

comment 3y ago · link · parent

I'm sure it's against the rules but why is it unethical

comment 3y ago · link · parent

What's unethical about it

comment 3y ago · link · parent

I sometimes have to write code or ask technical questions from product specifications. If those specifications are too new (for example right now I'm working with openrtb 2.6), chatgpt won't have any information about them. The ability to pull up a pdf file and ask windows about examples of a particular field in a particular 200 page spec document would greatly improve development for me. That's the feature I'm most excited about (though you can actually already do this with Bing, through edge)

comment 3y ago · link · parent

Finally; been waiting for this for a while. I wonder if Apple will try to catch up or not

comment 3y ago · link · parent

At release, the police mechanics were the most immersion breaking part for me. They would just appear randomly when you were wanted and disappear if you turned around.

>Updated PC system requirements. A SSD is now required to run the game

lol they finally gave in

comment 3y ago · link · parent

> Avoid buying the lowest tier pricing

Easy to say when you have money

comment 3y ago · link · parent

They should be broken up to increase competition. European (and asian) airlines provide better service at lower cost. The US airlines get bailed out every 10 years and so there is no incentive for them to improve their companies at all.

comment 3y ago · link · parent

> Source that they are they ignoring their core competency?

Have you flown on an airplane in the last 10 years? I'd rather drive 15 hours to Florida than deal with the fucking airlines

comment 3y ago · link · parent

You're living in 1999 dude. Amazon owns all the business infrastructure these days

comment 3y ago · link · parent

Would be cool to see some examples

comment 3y ago · link · parent

Not if string literals are prepended with `STR.`. Old strings won't be affected

comment 3y ago · link · parent

Not all variables are user data

comment 3y ago · link · parent

Oracle has broken compatibility between versions before, at least in the runtime. URL Decoder's constructor was taken private after JDK 11:

https://docs.oracle.com/en/java/javase/11/docs/api/java.base...

https://docs.oracle.com/en/java/javase/17/docs/api/java.base...

comment 3y ago · link · parent

I just want important information boiled down to code examples and lists of features for me. I don't need to read an essay on the history of string interpolation

comment 3y ago · link · parent

I don't see why the next step can't be more capitalism. The private ownership of property and the investment structure as it exists has resulted in billions of people being lifted out of poverty. Why wouldn't we want to continue doing that? Because people in America saw a relative decrease in buying power over a generation? Is the rest of the world supposed to stop improving the lives of their citizens?

comment 3y ago · link · parent

Plus, prepending the string with `STR.` changes the syntax entirely. Those strings are still invalid if you don't prepend `STR.` (which is another thing I hate, but not quite as much).

In C#, the string `"""Hello world"` is invalid, but `@"""Hello world"` is, because double quotes are valid with verbatim string literals.

1
383940
55