[P4-dev] typedef, P4-16 & p4c compiler

Mihai Budiu mbudiu at vmware.com
Fri Jun 9 12:34:00 EDT 2017


int is a keyword, but it is also a type.
struct is not a type. The same holds for header in P4.

Mihai

From: hemant at mnkcg.com [mailto:hemant at mnkcg.com]
Sent: Friday, June 9, 2017 2:54 AM
To: 'Andy Fingerhut' <andy.fingerhut at gmail.com>
Cc: Mihai Budiu <mbudiu at vmware.com>; 'p4-dev' <p4-dev at lists.p4.org>
Subject: RE: [P4-dev] typedef, P4-16 & p4c compiler

I do know the header is a keyword in P4-16, but so are int and long in C.  The C preprocessor totally allows, for example, a “typedef int distance;”.   The issue is because the header may be like a struct in C.   My use case is typedef a new type from a header and then use the new type as several headers with different set of bits.

Hemant

From: Andy Fingerhut [mailto:andy.fingerhut at gmail.com]
Sent: Thursday, June 08, 2017 8:52 PM
To: hemant at mnkcg.com<mailto:hemant at mnkcg.com>
Cc: Mihai Budiu <mbudiu at vmware.com<mailto:mbudiu at vmware.com>>; p4-dev <p4-dev at lists.p4.org<mailto:p4-dev at lists.p4.org>>
Subject: Re: [P4-dev] typedef, P4-16 & p4c compiler

I believe the string "header" is a keyword in P4-16, and probably cannot be the name of a type.

You can define a header type with name "ipv4_t", and then typedef another type name to be the same as that one like so:

header ipv4_t {
    // your fields here
}
typedef ipv4_t another_type_name_t;

then use 'another_type_name_t' any place that you would otherwise use 'ipv4_t'.

Andy

On Thu, Jun 8, 2017 at 1:42 PM, <hemant at mnkcg.com<mailto:hemant at mnkcg.com>> wrote:
typedef header foo_t;

From: Mihai Budiu [mailto:mbudiu at vmware.com<mailto:mbudiu at vmware.com>]
Sent: Thursday, June 08, 2017 4:40 PM
To: hemant at mnkcg.com<mailto:hemant at mnkcg.com>; 'p4-dev' <p4-dev at lists.p4.org<mailto:p4-dev at lists.p4.org>>
Subject: RE: typedef, P4-16 & p4c compiler

Can you post a code fragment (even if it does not work) showing what you want to achieve?

Mihai

From: hemant at mnkcg.com<mailto:hemant at mnkcg.com>
Sent: Thursday, June 8, 2017 1:19 PM
To: 'p4-dev'<mailto:p4-dev at lists.p4.org>
Cc: Mihai Budiu<mailto:mbudiu at vmware.com>
Subject: typedef, P4-16 & p4c compiler

If C preprocessing is supported in P4, including P4-16, is the P4-16 “header” possible to be typedefed?  I am not sure what the type is because the header is in the P4 library.  If a C preprocessor allows any C type such as “int” to be typdefed, why not the P4-16 header?

Thanks,

Hemant

_______________________________________________
P4-dev mailing list
P4-dev at lists.p4.org<mailto:P4-dev at lists.p4.org>
http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org<https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.p4.org_mailman_listinfo_p4-2Ddev-5Flists.p4.org&d=DwMFaQ&c=uilaK90D4TOVoH58JNXRgQ&r=tGW6TKXajnoXSyy1S1P4DHGPe8sj54GGvw-b21n7aWg&m=rBRTqD1_dhDUOEybSy05BurT1i2E_alMsKeGQNHNRPU&s=0ocByjszt6s5iCDdhYiYJCA2vSMV-Z6sLSqtYbL-S1I&e=>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20170609/9fff7446/attachment-0002.html>


More information about the P4-dev mailing list