-9

Here is a simple example program which demonstrates what I want to asking for:

class A {
public:
    int writemem(FilInfo* file, IN BYTE* mem, IN DWORD memSize, BYTE obfs=0, BOOL bEnc=TRUE);
};

void main() {
...
    (this->writemem(file, mem, memSize), obfs); // does not print compilation error!
...
}

How is the above code compilable? Compiling the above program was successful although it does not work what I intended. I am working on Windows 8.1 with VisualStudio SDK 7.1.

freddy
  • 413
  • 1
  • 8
  • 18
  • 5
    [Don't write `void main()`.](https://stackoverflow.com/a/204483/2486888) –  Jun 08 '18 at 01:50
  • 4
    `main` returns `int`. And you can't randomly call a member function without an object. The code you've posted is nonsense, so there's no sensible answer anyone can give. Post code that shows the problem when compiled. – Pete Becker Jun 08 '18 at 01:51
  • Why do you expect there to be a compiler error? – NathanOliver Jun 08 '18 at 01:52
  • 3
    @NathanOliver -- `this` isn't valid where it's used here. Of course, that probably would have generated an error message, except that this code isn't the actual code under discussion. – Pete Becker Jun 08 '18 at 01:52
  • 2
    _"Compiling the above program was successful"_ No, that code did not compile successfully. If you compiled something successfully, it's not what you're showing here. – Drew Dormann Jun 08 '18 at 01:58

1 Answers1

-1

I think this is a mcve we can talk about:

#define IN 
struct FilInfo {};
struct DWORD {};
struct BYTE {
    BYTE() {}
    BYTE(int i) {}
    BYTE(const BYTE& i) {}
};
enum BOOL {
    TRUE,
    FALSE
};

class A {
public:
    int writemem(FilInfo* file, IN BYTE* mem, IN DWORD memSize, BYTE obfs=0, BOOL bEnc=TRUE) {return 0;}
};

int main() {
    FilInfo* file;
    BYTE* mem;
    DWORD memSize;
    BYTE obfs;
    A* a;
    BYTE obfs2 = (a->writemem(file, mem, memSize), obfs); // does not print compilation error!

    return 0;
}

Why should it generate compiler errors or warnings? This code is valid.

(a->writemem(file, mem, memSize), obfs) is a statement consisting of two statements seperated by a comma operator. A variable name is a valid statement.

First a->writemem(file, mem, memSize) is called. Then obfs is called and finally obfs is passed from (a->writemem(file, mem, memSize), obfs) to obfs2.

Thomas Sablik
  • 15,600
  • 7
  • 29
  • 55